[英]How to prevent xlim from changing the height using geom_curve?
I have the following code: 我有以下代码:
library(tidyverse)
data_frame(x = 1:5, x1=x+1, c = c('a','a','a','b','b')) %>%
ggplot() +
geom_curve(aes(x = x, xend= x1, y = 0, yend = 0), curvature = -1.3, alpha=.2) +
facet_wrap(~ c, ncol=1)
but I would like to tweak the limits of the y axis to cut the background area above ~ .1. 但是我想调整y轴的极限以将背景区域切割到〜.1以上。
I tried to do this: 我试着这样做:
data_frame(x = 1:5, x1=x+1, c = c('a','a','a','b','b')) %>%
ggplot() +
geom_curve(aes(x = x, xend= x1, y = 0, yend = 0), curvature = -1.3, alpha=.2) +
facet_grid(c ~ .) +
ylim(0,.35) +
facet_wrap(~ c, ncol=1)
but it simply rescales the archs based on the values in ylim
. 但它只是根据ylim
的值ylim
。 How can I prevent this behavior? 我该如何防止这种行为?
coord_fixed()
has arguments that allow you to control precisely what you would like to have here. coord_fixed()
具有允许您精确控制此处所需内容的参数。
See also http://ggplot2.tidyverse.org/reference/coord_fixed.html for reference. 另见http://ggplot2.tidyverse.org/reference/coord_fixed.html以供参考。
Unfortunately, it is however not possible to use your x
and x1
in a dynamic way inside coord_fixed()
. 不幸的是,不可能在coord_fixed()
内部以动态方式使用x
和x1
。
As long as you are fine putting absolute values ( 0.6
and 6.4
below), you can however do something like this: 只要你把绝对值(下面的0.6
和6.4
)设置得很好,你就可以这样做:
data_frame(x = 1:5, x1 = x+1, c = c('a','a','a','b','b')) %>%
ggplot(.) +
geom_curve(aes(x = x, xend = x1, y = 0, yend = 0), curvature = -1.3, alpha = .2) +
facet_grid(c ~ .) +
coord_fixed(ratio = 7, xlim = c(0.6, 6.4), ylim = c(0, 0.12), expand = FALSE) +
scale_y_continuous(breaks = c(0, 0.1))
Assuming this looks like what you would want it to look like, note that I set expand = FALSE
to start ylim
at zero, and added buffers to xlim
(0.4) and the upper bound of ylim
. 假设这看起来像你想要它看起来像,请注意我设置expand = FALSE
以启动ylim
为零,并添加缓冲区到xlim
(0.4)和ylim
的上限。
I have modified the default ratio
value from 1 to 7, to scale you back down from the 0.7 to 0.1, which is what I understand you would like to have in the end. 我已经将默认ratio
值从1修改为7,以便将您从0.7缩小到0.1,这是我最终想要了解的内容。 ratio = 1
would imply that you have the same scale (same distances) on the y-axis as on the x-axis (which is what you refer to as re-scaling I believe). ratio = 1
意味着您在y轴上具有与在x轴上相同的比例(相同距离)(这就是您所说的重新缩放我认为)。
Finally I had to add the manual breaks for the y-axis (to have fewer ones), such that the grid boxes would be a bit larger, which again is just what I infer as your possible wish. 最后,我不得不为y轴添加手动中断(以减少更多),这样网格框会有点大,这也是我推断的可能的愿望。
用coord_fixed(ylim=c(0, 0.35))
ylim(0,.35)
替换ylim(0,.35)
是否ylim(0,.35)
要求?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.