How to control aspect ratios and scales of facette

2019-08-09 22:47发布

I want to facet three plots in rows of a single column using ggplot2, as illustrated below.

library(ggplot2)    
df <- data.frame(x=rep(1,3), y=rep(1,3), z=factor(letters[1:3]))
p <- ggplot(df, aes(x, y)) + geom_point() + facet_grid(z ~ .)
p

p.png

There are two problems with this output. Most importantly, I want to control the scales of the x and y axes, in this case to make them the same i.e. a single unit should measure the same distance on both x and y axes.

The second issue is the colliding lables for y axis of the facetted plots. Bonus points for solving that, but full credit for the scale/aspect ratio problem.

标签: r ggplot2
1条回答
女痞
2楼-- · 2019-08-09 23:01

I think you are looking for coord_fixed

library(ggplot2)    
df <- data.frame(x=rep(1,3), y=rep(1,3), z=factor(letters[1:3]))
p <- ggplot(df, aes(x, y)) + geom_point() + facet_grid(z ~ .)
p + coord_fixed(ratio=1)

enter image description here

查看更多
登录 后发表回答