我需要帮助将图形处理为多个pdf页面。这是我当前的代码:

file <- read.csv(file="file.csv")
library(ggplot2)
library(gridExtra)
library(plyr)

gg1 <- ggplot() +
  geom_line(aes(x=TIME, y=var1, colour = "z1"), file) +
  geom_line(aes(x=TIME, y=var2, colour = "z2"), file) +
  geom_point(aes(x=TIME, y=var3), file) + facet_wrap( ~ ID, ncol=5)+
  xlab("x") +
  ylab("Y") +
  ggtitle(" x ") + scale_colour_manual(name="Legend",
    values=c(z1="red", z2 ="blue")) + theme(legend.position="bottom")
gg10 = do.call(marrangeGrob, c(gg1, list(nrow=4, ncol=4)))
ggsave("need10.pdf", gg10)

这是创建的图像,没有拆分我的图像

r - 如何使用ggplot2在多个pdf页面中获取图-LMLPHP

我希望有一个代码,可以在多页中以4 x 4布局显示我的绘图。我的代码的最后两行需要调整,我自己也不知道如何解决。

最佳答案

ggplus包装器似乎可以完成您想做的事情。我在下面的代码块中从原始代码中更改了几件事:facet_wrap被注释掉了,并且file被移到ggplot,因此不必在每个geom_*中重新指定它:

gg1 <- ggplot(file) +
  geom_line(aes(x=TIME, y=var1, colour = "z1")) +
  geom_line(aes(x=TIME, y=var2, colour = "z2")) +
  geom_point(aes(x=TIME, y=var3)) +
  # facet_wrap( ~ ID, ncol=5) +
  xlab("x") +
  ylab("Y") +
  ggtitle(" x ") +
  scale_colour_manual(name="Legend",
    values=c(z1="red", z2 ="blue"),
    labels=c("X","Y")) +
  theme(legend.position="bottom")

devtools::install_github("guiastrennec/ggplus")
library(ggplus)
pdf("need10.pdf")
gg10 <- facet_multiple(plot=gg1, facets="ID", ncol = 4, nrow = 4)
dev.off()

r - 如何使用ggplot2在多个pdf页面中获取图-LMLPHP
r - 如何使用ggplot2在多个pdf页面中获取图-LMLPHP

关于r - 如何使用ggplot2在多个pdf页面中获取图,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38858830/

10-09 22:28