[英]How to create multiple plot from a list which contain List of dataframe in R
until now i am stuck at looping and saving a ggplot from List i have looked at the another question but it did not working.直到现在我一直在循环并从 List 中保存一个 ggplot 我已经查看了另一个问题,但它没有工作。
myplots=list()
par(mfrow = c(1, 5))
for (i in 1:5) {
#name=paste("ggp", i, sep = "_")
p1 =ggplot(Turbine[[i]],
aes(x=Turbine[[i]]$TS,
y=Turbine[[i]]$Pv..turbine))+
geom_point(size=1)+
ggtitle(names(Turbine[i])
)
print(i)
print(p1)
myplots[[i]]= p1
}
multiplot(plotlist=myplots,cols=5)
plot_grid(ggp_1,ggp_2,ggp_3,ggp_4,ggp_5) #trying to save ggplot as variable name
the problem i got is when i want to start plot of multiple plot in 1 drawing.我遇到的问题是当我想在一张图纸中启动多个 plot 的 plot 时。 i want to have 5 column of plots.
我想要 5 列图。
maybe s lapply func.也许 s lapply 功能。 is good?
很好?
let the data be让数据成为
Turbine=list of listname
first listname= name(Turbine[1])
view(Turbine [[1]])
TS Pv..turbine
1 20
2 20
3 24
4 19
so所以
Create something like your list:创建类似于您的列表的内容:
Turbine = lapply(1:5,data.frame(TS=1:10,"Pv..turbine"=runif(10))
You can use the plotlist=
argument in plot_grid, note, you don't need par(mfrow=..)), thats meant for base R plots and also you don't need to use the $
inside aes
:您可以在 plot_grid 中使用
plotlist=
参数,注意,您不需要 par(mfrow=..)),这适用于基本 R 图,而且您不需要使用aes
内的$
:
library(cowplot)
library(ggplot2)
myplots=list()
for (i in 1:5) {
myplots[[i]] = ggplot(Turbine[[i]],
aes(x=TS,y=Pv..turbine))+
geom_point(size=1)
}
plot_grid(plotlist=myplots,ncol=5)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.