相关疑难解决方法(0)

使用 R 中的 ggplot2 在分类散点图中添加水平线

我正在尝试为 3 个组绘制一个简单的散点图,每个组具有不同的水平线(线段):例如,组“a”的 hline 为 3,组“b”的 hline 为 2.5,hline 为组“b”。 “c”组为 6。

library(ggplot2)
df <- data.frame(tt = rep(c("a","b","c"),40),
             val = round(rnorm(120, m = rep(c(4, 5, 7), each = 40))))
ggplot(df, aes(tt, val))+
geom_jitter(aes(tt, val), data = df, colour = I("red"), 
position = position_jitter(width = 0.05))
Run Code Online (Sandbox Code Playgroud)

我真的很感谢你的帮助!

r scatter line ggplot2 categorical-data

6
推荐指数
1
解决办法
3757
查看次数

标签 统计

categorical-data ×1

ggplot2 ×1

line ×1

r ×1

scatter ×1