r - ggplot 图例列表大于页面

标签 r ggplot2 adobe-illustrator

我在 R 中有一个图,其中有大量样本组,因此图例大于页面大小并被截断。我知道这不是出版质量,但我需要知道颜色才能在 Illustrator 中制作图例。

有没有办法使页面尺寸更大或以某种方式更改图例格式,以便我可以包含所有键?这样做的原因是,我可以在 Illustrator 中打开 PDF 并获取每个样本的颜色,以创建将要发布的新图例。我想也许有一个剪贴蒙版,并且实际的图例将被保留,但是当我在 Illustrator 中打开时,图例实际上在页面末尾被剪切了1。

Here is one exmple where the legend goes beyond the graph and the page size and is therefore cut off.

正如下面评论中所建议的,我进行了多次尝试,这有助于打破图例,但现在整个页面都只是图例。

ggplot(purine.n, aes(x=variable, y=value, colour=metabolite_gene, shape=variable))
+geom_abline(slope=0)
+geom_point(size=4, position=position_dodge(width=0.08))
+scale_y_continuous(limit=c(-3.5,5.5), breaks=c(-3,-2,-1,0,1,2,3,4,5))
+scale_shape_manual(values=c(16,17,17), guide=F)
+theme_bw()
+theme(legend.key=element_blank(), legend.key.size=unit(1,"point"))
+guides(colour=guide_legend(nrow=16))

最佳答案

正如评论中所建议的,nrow 是我问题的答案。我必须调整该值以获得正确的行数以适合我的图例。下面是已完成的有效代码。我需要做更多调整,例如更改页面大小以帮助使事情看起来更好,但这超出了这个问题的范围。

ggplot(data.n, aes(x=variable, y=value, colour=metabolite_gene, shape=variable))
+geom_abline(slope=0)+geom_point(size=4, position=position_dodge(width=0.08))
+scale_y_continuous(limit=c(-3.5,5.5), breaks=c(-3,-2,-1,0,1,2,3,4,5))
+scale_shape_manual(values=c(16,17,17), guide=F)
+theme_bw()
+theme(legend.key=element_blank(), legend.key.size=unit(1,"point"))
+guides(colour=guide_legend(nrow=30))

fixed legend with nrow

关于r - ggplot 图例列表大于页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30083002/

相关文章:

r - 在椭圆和矩形内生成数据

r - 如何在ggplot2中用不同因素绘制一维点的密度

r - geom_path() 拒绝跨越 coord_polar() 中的 0/360 线

r - 可以强制不出现的元素显示在 ggplot 图例中吗?

html - 如何制作悬停命令 = 悬停时的形状?

javascript - 打开时运行命令的 Illustrator 文件

R HoltWinters 预测包 - 避免过度拟合数据

r - 当月份是 3 个字符变量时,在 R 中转换为日期的最佳方法?

r - 使用 ggplot2 绘制日期时遇到问题

css - Adobe Illustrator 删除了我在 svg 图像上的类名。我怎样才能防止这种情况发生?