看到论坛上好多人在问ggplot2怎么画1页多图,par参数在这里不起作用。一种方法是通过分面facet_grid,还有一种方法是通过视图窗口viewport和矩形网格grid,具体代码如下(以第二周作业为例):
library(ggplot2)
p <- ggplot(data = diamonds, aes(x = clarity, fill = cut))
p1 <- p + geom_histogram(postition = "stack") + scale_y_continuous(breaks = seq(0, 
    12000, 2000))
p2 <- p + geom_histogram(position = "fill")
p3 <- p + geom_histogram(position = "dodge")
grid.newpage()
pushViewport(viewport(layout = grid.layout(2, 2)))
vplayout = function(x, y) viewport(layout.pos.row = x, layout.pos.col = y)
print(p1, vp = vplayout(1, 1))
print(p2, vp = vplayout(1, 2))
print(p3, vp = vplayout(2, 1:2))

ggplot2如何实现1页多图 

相关文章:

  • 2021-04-02
  • 2021-12-24
  • 2021-06-04
  • 2021-11-24
  • 2021-11-27
  • 2021-06-05
  • 2021-06-16
猜你喜欢
  • 2022-01-03
  • 2021-10-12
  • 2022-12-23
  • 2022-01-07
  • 2021-07-24
  • 2021-12-29
  • 2022-12-23
相关资源
相似解决方案