【问题标题】:How to increase the ggplot2 figures resolution如何提高 ggplot2 数字分辨率
【发布时间】:2019-11-21 14:50:13
【问题描述】:

我正在尝试使用 RStudio 创建一个 300 dpi 的 ggplot2 图。我试过命令

tiff("test.tiff", units="in", width=5, height=5, res=300)

ggplot(Rrib, aes(YEAR, CLUSTER)) + geom_tile(aes(fill = SAMPLE_TYPE), colour="black", size = 1.3)+ scale_fill_manual(values = c("BOTH" = "red2", "ENV" = "forestgreen", "AFP" = "orange", "NONE" = "white"))

dev.off()

但是,R studio 没有在绘图区域显示任何输出。 非常感谢您的帮助

【问题讨论】:

  • myplot <- ggplot(...) 然后ggsave(myplot, "test.tiff", width = 5, height = 5, res = 300)

标签: r ggplot2


【解决方案1】:

使用ggsave():

ggplot(Rrib, aes(YEAR, CLUSTER)) + geom_tile(aes(fill = SAMPLE_TYPE), colour="black", size = 1.3)+ scale_fill_manual(values = c("BOTH" = "red2", "ENV" = "forestgreen", "AFP" = "orange", "NONE" = "white"))
ggsave(‘test.tiff’,dpi=300)

事实上,默认 dpi 是 300,但我包含了这个参数,以防你以后想更改它。

【讨论】:

  • 我替换了逗号来修复它,但问题是我没有在情节部分以图表的形式输出
  • 请在这方面提供帮助
  • @SDSO 需要您的输入,我尝试了命令在图像中保存 8.17 x 5.55,但绘图区域中没有出现任何内容
  • 尝试将ggplot分配给对象p <- ggplot(Rrib, aes(...,然后使用ggsave:ggsave('test.tiff', p, device = "tiff", dpi = 200)
  • 它应该保存在您的工作目录中。但是如果您可以在file = 术语中指定路径。例如ggsave('c:/documents/my_project/test.tff', p, device = "tiff", dpi = 200)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-04
  • 2013-01-06
  • 1970-01-01
  • 1970-01-01
  • 2020-06-04
  • 2010-10-19
相关资源
最近更新 更多