IDEMSInternational / R-Instat

A statistics software package powered by R
http://r-instat.org/
GNU General Public License v3.0
38 stars 103 forks source link

The Climatic > PICSA > Rainfall graphs again #5309

Closed rdstern closed 5 years ago

rdstern commented 5 years ago

image

This is a multiple graph, i.e. there are 2 variables plotted, showing the start and the end of the rains together. (It is with the Samaru - Nigeria data from the library. The steps to get here are in the draft climatic guide.)

It isn't quite what I would like, because the y-axis doesn't show dates - it is numeric only. I can get the dates and the line(s). Here they are: image

You notice the single line, rather than the separate line for the 2 means. If that can be fixed, then I have the graph I need. So that is one request. David says that might be reasonably easy.

When, with the above graph, I return to the dialogue and click on Single and then on Plot Options I get this message:

instat Developer error: More than one state of control ucrChkExpand satisfies it's condition. Cannot determine how to set the control from the RCode. Modify conditions so that only one state can satisfy its conditions. OK

Then it did let me into the sub-dialogue. I chose Themes and not to display the Legend and that works.

I then tried adding Hline as additional layers, having first established the mean of the start and end myself. I can get it to display if I don't have dates as the Y-axis, but not if I do.
I also tried (with dates) adding the end as a second layer and it says I need to give a date origin. Adding layers is not easy, when dates are displayed.

I realise @stevenndungu is working on #5120, (also on this dialogue) but have made these separate, because they seem a bit different. And possibly harder to fix?

stevenndungu commented 5 years ago

@rdstern, @dannyparsons I chose to combine this issue with the issue of means and median lines not being drawn correctly when a facet is done. While the later is fixed, I thought the changes could roll over and fix this issue as well. However, to my suprise, it didn't - due to obvious reasons, the code implementation is not consistently borrowed over. By this I mean, while for the faceting we have a grouping factor, in this case, the data is stacked automatically hence no grouping element included.

After careful investigation with @maxwellfundi on the prior and how we can solve this. We ought ; 1) If we want to plot the above plot quickly and easily (user-friendly) using the multiple receiver after creating the start and end of rains columns or more columns then we need to:-. i) Enable the PICSA options button when we have a multiple receiver. This allows us to be able to add the lines (mean, median, etc) to the start and end of rains respectively for this case. NB - We have tested if this could result in any bug associated with enabling the PICSA sub-dialogue option but found none. @dannyparsons @rdstern @maxwellfundi suggests its time we re-evaluate why we need to disable the plot options whilst using multiple receiver.

2) If we want to plot the above graph, using the single receiver then we will need to an extra step of reshaping the data using the stack dialog.

We now have these two options which produce the same result as shown

image

We would like to hear what your thoughts are on this matter.

stevenndungu commented 5 years ago

Code generating above plot `# Code run from Script Window Samaru56t_by_year <- data_book$get_data_frame(data_name="Samaru56t_by_year", stack_data=TRUE, id.vars="year", measure.vars=c("start_doy","end_rains"))

Samaru56t_by_year <- Samaru56t_by_year %>% group_by(variable) %>% dplyr::mutate(.mean_y=mean(x=value, na.rm=TRUE))

last_graph <- ggplot2::ggplot(data=Samaru56t_by_year, mapping=ggplot2::aes(x=year, y=as.numeric(x=value), colour=variable)) + ggplot2::geom_line(size=0.8) + ggplot2::geom_point(size=3, colour="red") + ggplot2::geom_hline(mapping=ggplot2::aes(yintercept=.mean_y), size=1.5) + ggplot2::geom_label(mapping=ggplot2::aes(x=-Inf, y=.mean_y, label=paste("Mean:", round(x=.mean_y))), hjust=0, vjust=-0.3) + ggplot2::theme(panel.grid.major=ggplot2::element_line(colour="lightblue", linetype="longdash", size=1), panel.grid.minor=ggplot2::element_line(colour="lightblue", linetype="longdash", size=1), panel.border=ggplot2::element_rect(colour="black", fill="NA", size=0), axis.text.x=ggplot2::element_text(angle=90, size=12, vjust=0.4), axis.title.x=ggplot2::element_text(size=14), axis.title.y=ggplot2::element_text(size=14), title=ggplot2::element_text(size=20), plot.subtitle=ggplot2::element_text(size=15), plot.caption=ggplot2::element_text(size=8), axis.text.y=ggplot2::element_text(size=12), panel.background=ggplot2::element_rect(colour="white", fill="white", size=0.5, linetype="solid")) + ggplot2::xlab(label="") + ggplot2::ylab(label="")

data_book$add_graph(graph_name="last_graph", graph=last_graph, data_name="Samaru56t_by_year")

data_book$get_graphs(data_name="Samaru56t_by_year", graph_name="last_graph")`

dannyparsons commented 5 years ago

Your additional group_by looks correct, if that can be added correctly when using multiple columns (and removed when not) then that looks good. I also agree on enabling Plot Options generally for multiple columns.

stevenndungu commented 5 years ago

@dannyparsons are you suggesting we have the ability to have this nature of plots when using multiple receiver only? Implying we eliminate the option of stacking the data first (definitely a longer process to achieve the same but works)

stevenndungu commented 5 years ago

Also we can discuss on the upper and lower limit for the date tab (in the sub-dialogue)

dannyparsons commented 5 years ago

If the data is already stacked then it should be easier because the columns in the data match easily to grouping columns etc. I expect we don't need to implement anything special for it to work with stacked data. I think the multiple columns will be a more common option used so if it works in that case then great. I just wanted to make sure your changes means it still works for a simple graph of just one line with data in standard form.

dannyparsons commented 5 years ago

For the dates its a bit tricky because the column of doy is just numeric and then its transformed into a date as a "trick" to get it to display nicely. So the date is set to the year 2000, I think, but the user shouldn't have to know that, they should just be able to say "1 March" and "1 Oct" as limits, for example. It shouldn't be that difficult just more work on the code. I can't remember how far we got on implementing this already?

rdstern commented 5 years ago

Is this being added to the next Version?

maxwellfundi commented 5 years ago

Let me check with @dannyparsons and @stevenndungu , I hope it will

stevenndungu commented 5 years ago

Yes, this should be added to the next version. It is actually just code tidying, which by now its good.