[英]multiple plots with ggplot2 in r
I have a list of 12 dataframes: 我列出了12个数据框:
[1] X2016_kvish_1_10t
[2] X2015_kvish_1_10t
[3] X2014_kvish_1_10t
[4] X2013_kvish_1_10t
[5] X2012_kvish_1_10t
[6] X2011_kvish_1_10t
# with 6 more ...
and I want to plot them with the multiplot
function (ggplot2). 我想用
multiplot
绘图功能(ggplot2)绘制它们。 for example, this is a single plot: 例如,这是一个图:
ggplot(data = X2015_kvish_1_10t) +
geom_line(mapping = aes(
x = date, y = X2015_kvish_1_10t$nefah), colour = "blue") +
ylab("Traffic Counts (quantity)")+ ggtitle("Traffic Counts")+
geom_point(mapping = aes(
x = date, y = X2015_kvish_1_10t$day_mean , color = "blue"))
how can I plot them together so I can see the 12 at the same time and I won't need to write the same functions 12 times ? 我怎样才能将它们绘制在一起,以便我可以同时看到12个,而我又不需要编写12次相同的函数?
if p
is your plot, and ld
the list of data.frames, you could do: 如果
p
是你的阴谋,和ld
data.frames的列表,你可以这样做:
grid.arrange(grobs = lapply(ld, "%+%", e1 = p))
(untested, for lack of reprex) (未经测试,因为没有reprex)
But note that you should never have $
inside aes()
. 但是请注意,在
aes()
绝对不能包含$
。 And, of course, facetting is probably the better option. 当然,刻面可能是更好的选择。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.