ggplot以固定宽度和自动高度保存

时间:2015-05-26 12:37:37

标签: r ggplot2 r-grid

我在ggplot2中使用固定宽高比为所有方面创建了一个图。 当我保存绘图时,我想指定宽度,并自动计算高度。 在调整绘图大小以适合保存的图像时,我希望保存的图像可以调整大小以适合绘图。 这怎么可能? 在下图中我只想要具有绿色背景的部分,我希望它具有特定的宽度。

感谢您的帮助。

library(ggplot2)

p <- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +
  facet_grid(Species ~ .) +
  geom_point() +
  theme(aspect.ratio = 2 / (sqrt(5) + 1), plot.background = element_rect(fill = "#ccffcc"))

ggsave(filename = "plot.png", plot = p, width = 8)

show(p)

enter image description here

0 个答案:

没有答案
相关问题