How to control the proportions and scales of ggplot2 faceted areas?

I want to highlight three graphs in the rows of one column using ggplot2, as shown 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 solution. Most importantly, I want to control the scales of the x and y axes, in this case make them the same, i.e. One unit should measure the same distance on both the x-axis and the y-axis.

The second problem is colliding matrices for the y axis of faceted graphs. Bonus points for solving this, but full credit for the problem of scale / aspect ratio.

+1
source share
1 answer

I think you are looking 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

+2
source

Source: https://habr.com/ru/post/1017170/


All Articles