PecanProject / pecan

The Predictive Ecosystem Analyzer (PEcAn) is an integrated ecological bioinformatics toolbox.
www.pecanproject.org
Other
202 stars 234 forks source link

Update parameter density plotting functions to use ggplot2 v>=9.2 #93

Closed dlebauer closed 9 years ago

dlebauer commented 10 years ago

The function plot.trait and its dependencies were written using the syntax of ggplot2 v 0.90.

Mostly this will require changing use of the opts() function to theme() and renaming theme_xx() functions to element_xx(). There is a comprehensive guide here: https://github.com/wch/ggplot2/wiki/New-theme-system

This should be very similar to the changes made when I updated the variance decomposition and sensitivity plots (0dde7f07757b82196c83a9b3d0634dd5cf56bebe)

To get a list of the warnings thrown by ggplot2 deprecated functions, try the following:

library(PEcAn.priors)
plot.trait("Vcmax", prior = list('norm',1,1), posterior.sample = rnorm(1000, 1.1, 0.5))
help(package = "PEcAn.priors")
?plot.trait
braczka commented 10 years ago

@dlebauer Hi David, thanks for posting. I am taking a look at this today. Do similar type functions exist for plotting the variance decomposition and sensitivity plots, where I want the prior/posterior results on the same plot as well?

dlebauer commented 10 years ago

This functionality should exist - have you looked at the code for these functions?

braczka commented 10 years ago

I haven't looked at the code that provides the SA and VD plots in detail, but did you have a script that uses the existing SA and VD plot functions in such a way to produce multiple results on the same plot? For example, what you have provided above should produce Figure 4 within your 2013 Ecological Monographs paper. I am looking to re-create Figures 6 and Figures 7 within your Monographs paper as well.

dlebauer commented 10 years ago

In this directory: https://github.com/dlebauer/pecan-archives/blob/master/manuscript/

the priors plots are in priors.Rnw and the rest of the results are in results.Rnw (btw this repository is a mirror of the archive: https://www.ideals.illinois.edu/handle/2142/34655)

braczka commented 10 years ago

@dlebauer The link appears to be broken for: https://github.com/wic/ggplot2/wiki/New-theme-system. It seems like the function works even with the deprecated version. Do I lose functionality without implementing the theme update?

dlebauer commented 10 years ago

@braczka I updated the link to the new ggplot2 theme system guide

Do I lose functionality without implementing the theme update?

Read the guide and let me know.

braczka commented 10 years ago

Sorry, I was making that out to be a lot harder than it was. I didn't realize that most of the functionality to plot multiple results for the SA and VD plots was built into the function itself (plot.variance.decomposition and plot.sensitivities) Thank you for being patient.

braczka commented 10 years ago

@dlebauer When using the plot.variance.decomposition() function for multiple sensitivity results I have been getting the following error: "Error: Incompatible lengths for set aesthetics: size" The two 'sensitivity.results.Rdata' output I used contain the same variables and quantile evaluations etc. I call the function as follows:

vd.plots <- plot.variance.decomposition(prior.sensitivity.results$variance.decomposition.output, post.sensitivity.results$variance.decomposition.output) pdf(file.path('~/code_stash/plot_theme_update', "variancedecomposition.pdf"), width = 11, height = 8) do.call(grid.arrange, c(vd.plots, ncol = 4)) dev.off()

As a side note, using the same 'sensitivity.results.Rdata' with the plot.senstivities() functions seems to work OK, as both response curves are displayed on the same figure correctly.

dlebauer commented 10 years ago

@braczka What have you tried in the way of debugging? Have you started updating the syntax as previously discussed?

braczka commented 10 years ago

@dlebauer For the plot.trait() function I did update the syntax because it gave deprecation warnings. I did not update the syntax within plot.variance.decomposition() because I didn't get any warnings. I am taking a closer look now. It looks like within the plot.variance.decomposition() it calls upon ggplot and not ggplot2.....

braczka commented 10 years ago

@dlebauer Did some more troubleshooting. Found that the error: Incompatible lengths for set aesthetics: size comes from the variable vd.plots$trait.plot. I am fairly sure the problem is occurring because of the size setting within vd.plots$trait.plot$layers as follows:

mapping: x = points, y = 1, label = trait.labels, hjust = 1 
geom_text: parse = FALSE, size = numeric(0) 
stat_identity:  
position_identity: (width = NULL, height = NULL)

Instances where the variance decomposition plot is created successfully the size = 4.6667. Still looking at this, not sure how to correct it.

braczka commented 10 years ago

I see where the size is assigned in the code to `size = fontsize$axis/3`` . Let me see if changing this fixes things.

braczka commented 10 years ago

@dlebauer Manually assigning the size gets rid of the incompatible lengths set aesthetics:size, and a vd plot is created but NOT with multiple data sets being passed in. It seems the functionality for plot.variance.decomposition() only works for 1 data set at a time, not for two data sets as:

vd.plots <- plot.variance.decomposition(prior.sensitivity.results$variance.decomposition.output,
post.sensitivity.results$variance.decomposition.output)
pdf(file.path('~/code_stash/plot_theme_update', "variancedecomposition.pdf"), 
width = 11, height = 8)
do.call(grid.arrange, c(vd.plots, ncol = 4))
dev.off()

When multiple data sets are passed into the function it assumes the second data set is the fontsize when passed to the function itself within ~/modules/uncertainty/plots.R: and overwrites it:

plot.variance.decomposition <- function(plot.inputs, fontsize = list(title = 18, axis = 14)) etc.

Do I have to pass in the inputs into the plot.variance.decomposition differently so that it recognizes it as multiple sensitivity analyses? I don't think this is a syntax update issue. It looks like the 'plot.sensitivities' function is more explicit in how multiple sensitivity analyses are passed in and this works for me.

plot.sensitivities <- function(sensitivity.plot.inputs,
                               prior.sensitivity.plot.inputs = NULL, ...){
  sa.samples <- sensitivity.plot.inputs$sa.samples
  sa.splines <- sensitivity.plot.inputs$sa.splines
  if(!is.null(prior.sensitivity.plot.inputs)) {
    prior.sa.samples <- prior.sensitivity.plot.inputs$sa.samples
    prior.sa.splines <- prior.sensitivity.plot.inputs$sa.splines

etc.

.....but still stuck on how to get 'plot.variance.decomposition' to work for multiple data sets.

dlebauer commented 10 years ago

@braczka yes, this functionality for plot.variance.decomposition has apparently been lost since v1.1 that supports the code in the results.Rnw file. You can checkout the file from commit b685f92b409d8e19f649dd52430f63849980cbd7 (perhaps git checkout b685f92 R/plots.R) or see 70ff in R/plots.R and follow that template, along with the plot.sensitivities function when you update plot.variance.decomposition.

mdietze commented 9 years ago

Reassigned to Betsy since she's familiar with ggplot and said she could work on this