3

I have created a plot in ggplot2 using a fixed aspect ratio for all facets. When I save the plot I want to specify the width, and have the height automatically calculated. At the moment the plot is resized to fit the saved image, but I want the saved image to be resized to fit the plot. How would this be possible? In the picture below I only want the part with green background, and I want it to have a specific width.

Thanks for any help.

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

Godisemo
  • 1,813
  • 2
  • 18
  • 26
  • i can't find the duplicate I'm thinking of, but this is close too http://stackoverflow.com/q/19357668/471093 – baptiste Jul 22 '15 at 20:37

0 Answers0