Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make my facets perfectly square?

Tags:

r

ggplot2

facets

I'm using facet_wrap with ggplot to create a plot of facets. My problem is that my facets always come out looking like very short, very wide rectangles, but I want them to be square so they are easier to understand. Ideally, I would like to specify the number of columns I desire, and have ggplot figure out what the height of the plot should be so that all the facets are square. Is this possible?

like image 308
andrew Avatar asked Jan 22 '14 21:01

andrew


1 Answers

Maybe aspect.ratio helps:

df <- data.frame(x = runif(100, 0,10), y = runif(100, 0, 50), z=gl(4,25))
ggplot(df, aes(x, y)) + 
  geom_point() + 
  facet_wrap(~ z, ncol = 4) + 
  theme(aspect.ratio = 1) # try with and without
like image 174
lukeA Avatar answered Nov 11 '22 12:11

lukeA