Combine plots in R

馋奶兔 提交于 2021-02-08 09:54:41

问题


I have several plots that I want to combine them together and add a title to the combined plot, but somehow I cannot combine them using R. (using RStudio)

  1. Combine two residual plots plotted by using plot(resid(lme)) where lme is a linear mixed model.
  2. Combine two interaction plots plotted by using interaction.plot(x1,x2,y) where x1 and x2 are the two independent variables, and y is the dependent variable.

I tried to store the plots as variables and use grid.arrange, but they cannot be stored into a variable (just produce the plot in the plot area).

i.e.

> int1 <- interaction.plot(data_pos_10$Day,data_pos_10$Drug,data_pos_10$Tumor.Volume,
+                  xlab="Day",ylab="Tumor Volume",main="Interaction Plot Batch 10",
+                  legend=F,
+                  col=c("red","red","green","black","blue"),
+                  lwd=2,
+                  lty=c(1,2,3,4,5))
> int1
NULL

回答1:


Before you do your plotting code, run par(mcol=c(2,1)) to stack them vertically or par(mcol=c(1,2)) to stack them horizontally.



来源:https://stackoverflow.com/questions/22309739/combine-plots-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!