[英]Plot several graphs in R
I am trying to plot automatically several graphs with ggplot.我正在尝试 plot 自动使用 ggplot 绘制几张图。 I want to make a total of 23 stacked bar plot.我想制作总共 23 个堆叠条 plot。
The original df ( train2016
) has variables in columns 25 to 48 and all of them have the values c(0, 1)
.原始 df ( train2016
) 在第 25 至 48 列中有变量,所有变量都具有值c(0, 1)
。
I want to represent on Y axis the month (given in a column) - X axis the result of the count of 0 or 1 value of each variable.我想在 Y 轴上表示月份(在列中给出)- X 轴是每个变量的 0 或 1 值的计数结果。
I cannot see the result and there is no error showing.我看不到结果,也没有错误显示。 This is the code I wrote.这是我写的代码。 I know there must be multiple errors我知道一定有多个错误
par(nfrow=c(4,6))
for (i in 25:48) {
datos22 <- train2016 %>%
group_by(month, train2016[i]) %>%
summarise(count= n()) %>%
ggplot(aes(fill=train2016[i], x=count,y=month)) +
geom_col() +
ggtitle(" ")
}
You can try ggsave
to save the graphs您可以尝试ggsave
保存图表
par(nfrow=c(4,6))
for (i in 25:48) {
datos22 <- train2016 %>%
group_by(month, train2016[i]) %>%
summarise(count= n()) %>%
ggplot(aes(fill=train2016[i], x=count,y=month)) +
geom_col() +
ggtitle(" ")
ggsave(paste0("plot_", i, ".png"))
}
Will save all the plots to independent files.将所有绘图保存到独立文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.