In ggplot2, the coord_fixed() coordinate system ensures that the aspect ratio of the data is maintained at a given value. Thus, the shape of the panel changes to save the data form. Meanwhile, coord_flip() swaps the plots. However, the graph in ggplot2 must have exactly one coordinate system, so these functions cannot be combined.
My question is:
Is there a way to combine the behavior of coord_fixed() and coord_flip() , resulting in a coordinate system with exchangeable x and y axes and a fixed aspect ratio of the data?
This is a popular question, however the general answer is incorrect:
It is usually suggested to use coord_flip() along with theme(aspect.ratio = 1) instead of coord_fixed() . However, according to the ggplot2 documentation, this parameter refers to the "aspect ratio of the panel". Thus, the data will change shape to maintain the shape of the panel.
I suspect this is a function that does not currently exist in ggplot2. But more importantly, I believe that the right decision, or at least the answer to this question, should be documented.
A quick minimal problem example:
library(ggplot2) x <- 1:100; data <- data.frame(x = x, y = x * 2) p <- ggplot(data, aes(x, y)) + geom_point() p
source share