我正在尝试复制一个相似的人物
我的数据看起来像这样
Category Value
A 2
A 3
A 4
A 2
A 4
B 2
B 1
B 6
C 1
C 2
C 3
C 3
我想绘制类别为X轴和y轴为值的分布。由于其中一些具有相似的值,因此使用stat_ecdf()可以很好地可视化类别的曲线分布,以水平移动相似点(类似于链接中的图)。
我在ggplot中使用了beeswarm图,但想使用stat_ecdf来获得位移分布(每个条目显示为每个类别的点)。并以红色添加中线。
我尝试过的
a <- ggplot(df, aes(x=Category, y=value)) +
stat_ecdf()+
scale_y_continuous() +
theme_light() +
theme(axis.text.x = element_text(angle = 90)) +
xlab('category') +
ylab('values')
a
答案 0 :(得分:0)
今天我的时间有点有限,但这也许可以为您指明正确的方向。
a <- ggplot(data = df,
aes(x = value)) +
stat_ecdf(geom = "point",
size = 1,
pad = FALSE) +
xlab("category") +
ylab("values") +
facet_wrap(~ Category,
scales = "free_x",
strip.position = "bottom") +
coord_cartesian(clip = "off") +
theme_minimal() +
theme(axis.text.x = element_blank(),
panel.grid.minor = element_blank(),
panel.grid.major = element_blank())
a
更新: 我玩了一些。希望这看起来更好。