我正在使用下面给出的代码使用ggplot在同一页面上绘制多个图形。而不是每个图都有自己的xlabel,ylabel,标题和图例描述,我只希望每个页面都有一个这样的图。我试图找到一个解决方案,但无济于事。有人可以让我知道,或将我指向相关主题吗?谢谢。
plots <- dlply(dacc, .(SIC), function(x){
ggplot(x, aes(x = PER)) +
geom_line(aes(y = MEAN, group = NLEAD, color = NLEADMEAN)) +
geom_line(aes(y = MED, group = NLEAD, color = NLEADMED)) +
xlab("(Total Asset Percentile Cutoff To Define Big Firms)") +
ylab("Mean Absolute Discretioary Accrual For Different Groups") +
ggtitle(paste("Mean ADA Across Groups For SIC = ", unique(x$SIC))) +
ylim(0, ymax/2)
})
ml <- do.call(marrangeGrob, c(plots, list(nrow = 2, ncol = 2)));
ggsave("my_plots.pdf", ml, height = 7, width = 13, units = "in");
编辑:
ggplot(dacc, aes(x = PER)) +
geom_line(aes(y = MEAN, group = NLEAD, color = NLEADMEAN)) +
geom_line(aes(y = MED, group = NLEAD, color = NLEADMED)) +
xlab("(Total Asset Percentile Cutoff To Define Big Firms)") +
ylab("Mean Absolute Discretioary Accrual For Different Groups") +
ggtitle(paste("Mean ADA Across Groups For SIC = ", unique(x$SIC))) +
ylim(0, ymax/2) +
facet_wrap(~SIC,nrow=2)
这显然更好,但是我面临着这个的多个问题。(1)在终端上,我可以看到仅显示xlab和ylab的图形。但是,如何保存图形?(2)我大约有50 SIC,所以有50 grpahs,因此我假设保存时,假设nrow = 10,我应该能够在每页上看到xlab和ylab。
如前所述,您应该在此处使用构面功能。例如:
facet_wrap(~SIC,nrow=2)
您的代码将变成这样:
ggplot(dacc, aes(x = PER)) +
geom_line(aes(y = MEAN, group = NLEAD, color = NLEADMEAN)) +
geom_line(aes(y = MED, group = NLEAD, color = NLEADMED)) +
xlab("(Total Asset Percentile Cutoff To Define Big Firms)") +
ylab("Mean Absolute Discretioary Accrual For Different Groups") +
ggtitle(paste("Mean ADA Across Groups For SIC = ", unique(x$SIC))) +
ylim(0, ymax/2) +
facet_wrap(~SIC,nrow=2)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句