-1

I have used ggplot2 to create plot. . Here plotmodel is a function which generates individual plot based on input and i use myplot which is a list to store the plots returned by plotmodel .

for (i in 1:le) {
myplot[[i]]<-plotmodel(df2,colnames(df2)[i],z[[i]],xnames[i])

}

I have also created a single plot called "plotinfec" .

My plots work fine if I execute individually. Can you please help or give suggestion on how can I display plotinfec and myplot in a single window .

Naveen Gabriel
  • 679
  • 2
  • 9
  • 25
  • i don't agree . Because I have mentioned the basic requirement what i need. And i have given the background of my problem and what I have done. One of the user understood and he has replied as well. Thanks. – Naveen Gabriel Sep 13 '18 at 13:03
  • It is very honorable of @Juan Antonio Roldán Díaz to have answered to this poorly asked question. Read the link which explains why it was worth to downvote your question. If you decide to make your question fully reproducible, I am absolutely up for removing the downvote. – tjebo Sep 13 '18 at 13:06
  • I did read it at the first instance. Actually i don't bother about downvote but respectfully I don't agree with your opinion. I showed it couple of my friends and they were able to follow it. Moreover, when people see this who are just starting out, it is easy to understand rather than seeing the whole code which might scare them off. I don't want to argue more. Thanks for the contribution. Keep supporting. Cheers – Naveen Gabriel Sep 13 '18 at 13:17
  • 1
    I agree it's not worth to argue here and that's not my intention. The reason why I am pointing out to the deficit of your question, it is a courtesy to the people who would like to help you to provide an MCVE, in order to make them work and spend as little of their valuable time as possible. Have a look at https://github.com/thomasp85/patchwork/issues/58, it might also aid your question. – tjebo Sep 13 '18 at 13:24
  • 3
    Possible duplicate of [How do I arrange a variable list of plots using grid.arrange?](https://stackoverflow.com/questions/10706753/how-do-i-arrange-a-variable-list-of-plots-using-grid-arrange) – tjebo Sep 13 '18 at 13:25

1 Answers1

1

Try this:

library(ggplot2)
library(gridExtra)
do.call(grid.arrange, c(list(plotinfec), myplot))

Example:

plotinfec <- ggplot(cars, aes(speed, dist)) + geom_density2d()
myplot <- list()
myplot[[1]] <- ggplot(cars, aes(speed, dist)) + geom_point()
myplot[[2]] <- ggplot(cars, aes(speed, dist)) + geom_hex()
myplot[[3]] <- ggplot(cars, aes(speed, dist)) + geom_line()

plotSW <- do.call(grid.arrange, c(list(plotinfec), myplot))
plot(plotSW)

enter image description here