作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想知道如何将单个主题数据点的垂直线连接到水平线。我的主要问题是 x 轴是分组的并且没有连续变量来指定线的位置。如果我让这条线从组 (xend) 下来,我只会为每个组得到 1 条垂直线。
这是我目前拥有的
ggplot() +
geom_point(data = df, aes(x = Group, y = Number, color = Group), position = "jitter") +
geom_hline(yintercept = 33.25)
geom_segment(data = df,
aes(x=Group,
xend=Group,
y=Number,
yend=33.25))
最佳答案
好消息是即将发布的 ggplot2 版本提供了 reproducible jitter .坏消息是geom_segment()
不允许抖动,所以使用 geom_linerange()
反而。
我们将能够指定 seed
像下面这样。希望版本快点发布!同时,您应该按照 https://stackoverflow.com/a/21922792/5397672 上的回答手动向数据添加抖动。 .
reprex::reprex_info()
#> Created by the reprex package v0.1.1.9000 on 2017-11-12
library(ggplot2)
set.seed(2)
dat <- iris[sample(1:nrow(iris), 20),]
ggplot(dat, aes(x=Species, y=Petal.Width)) +
geom_point(position = position_jitter(height = 0L, seed = 1L)) +
geom_hline(yintercept=0.75) +
geom_linerange(aes(x=Species, ymax=Petal.Width, ymin=0.75),
position = position_jitter(height = 0L, seed = 1L))
关于r - 来自分组散点图中数据点的ggplot2垂直线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47243288/
我是一名优秀的程序员,十分优秀!