如何控制刻面ggplot2图的纵横比和比例? [英] How to control aspect ratios and scales of facetted ggplot2 plots?
本文介绍了如何控制刻面ggplot2图的纵横比和比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用ggplot2在单列的行中绘制三个图,如下所示.
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
此输出有两个问题.最重要的是,我想控制x和y轴的比例,在这种情况下要使它们相同,即单个单位在x和y轴上应测量相同的距离.
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.
第二个问题是多面图的y轴碰撞标签.解决这个问题的要点是奖励,但要充分考虑比例/长宽比的问题.
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.
推荐答案
我认为您正在寻找 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)
这篇关于如何控制刻面ggplot2图的纵横比和比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文