0
plot_dist = function(df1, df2, features, nrows, ncols){
  fig_list = list()
  j=1
  for (feature in features){
    print(feature)
    fig = ggplot()+
      geom_density(data=df1,aes(feature),color="blue")+
      geom_density(data=df2,aes(feature),color = "black")
    fig_list[j] = list(fig)
    j = j+1  
   }
   multi_plot02 = marrangeGrob(grobs = fig_list, nrow = nrows, ncol = ncols)
   return(multi_plot02)
}

where df1, df2 are two dataframes with features from var_0 to var_199 in both dataframes.

I have tried noquotes method also, but no luck. If I am running it as single code then it is working but not in loop

I'm getting this, in multiplot: getting this, in multiplot

I expected this from the code, though it should be in multiplot: expectd this from the code, though it should be in multiplot

Z.Lin
  • 28,055
  • 6
  • 54
  • 94
  • 1
    Without a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), we can't run any of your code, and don't know how you're calling this function anyway. There's a good chance you need to be using tidyeval to write a function like this – camille Nov 20 '19 at 17:41
  • Probably this is a duplicate of the FAQ about [using variables to specify ggplot2 column names](https://stackoverflow.com/q/22309285/903061). Can't tell without any sample data or set-up info, but if `features` is a character vector it may be as simple as changing `aes` to `aes_string()`. Please provide a *small* reproducible example--I'm sure 20 rows each from each df should be plenty to illustrate the problem. – Gregor Thomas Nov 21 '19 at 03:32

0 Answers0