小编use*_*049的帖子

ggplot单独的传奇和情节

我正在使用网格包来放置我用ggplot2制作的图表:

library(ggplot2)
library(grid)

Layout <- grid.layout(nrow = 4, ncol = 4,
          widths = unit(1, "null"), 
          heights = unit(c(0.4, 0.8, 1.2, 1.2), c("null", "null", "null")))
grid.show.layout(Layout)

plot1 = ggplot(diamonds, aes(clarity, fill = color)) + 
            geom_bar() + 
            facet_wrap(~cut, nrow = 1)
print(plot1 + theme(legend.position = "none"), 
vp = viewport(layout.pos.row = 3, layout.pos.col = 1:4))
Run Code Online (Sandbox Code Playgroud)

问题是我想把图放在第三行(3,1) - (3,4)并将图例放在(4,4)位置.不幸的是,我真的找不到创建图例变量的方法.我在网上搜索,我得到的最接近的是使用旧的, + opts(keep = "legend_box")但已被弃用.

旧解决方案.

r legend ggplot2

14
推荐指数
1
解决办法
1万
查看次数

标签 统计

ggplot2 ×1

legend ×1

r ×1