作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 ggplot 中正确显示黄土线时遇到问题。我有几个变量,没有一个可以低于零,例如高度、重量和丰度。我试图用黄土线在 ggplot 中绘制这些数据。使用一些编造的数据:
library(ggplot2)
df <- as.data.frame(rep(1:7, each = 5))
df[,2] <- c(0,1,5,0,6,0,7,2,9,1,1,18,4,2,34,8,18,24,56,12,12,18,24,63,48,
40,70,53,75,98,145,176,59,98,165)
names(df) <- c("x", "y")
ggplot(df, aes(x=x, y=y)) +
geom_point() +
geom_smooth() +
scale_y_continuous(limits = c(-20,200))
ggplot(df, aes(x=x, y=y)) +
geom_point() +
geom_smooth() +
scale_y_continuous(limits = c(0,200))
最佳答案
我们可以计算覆盖ymin
的 aes stat_smooth
(注意与 geom_smooth
的区别):
ggplot(df, aes(x=x, y=y)) +
geom_point() +
stat_smooth(geom='ribbon', aes(ymin = ifelse(..ymin.. < 0, 0, ..ymin..)),
alpha = .3) +
geom_smooth(se = FALSE) +
scale_y_continuous(limits = c(-20,200))
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
#> `geom_smooth()` using method = 'loess' and formula 'y ~ x'
关于r - 在 ggplot 中设置黄土线置信区间阴影的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50471926/
我是一名优秀的程序员,十分优秀!