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)