gpt4 book ai didi

r - geom_dotplot 的点数错误

转载 作者:行者123 更新时间:2023-12-01 08:53:05 26 4
gpt4 key购买 nike

我的数据如下所示:

df.plot <-structure(list(color = structure(c(2L, 2L, 3L, 1L, 3L, 4L, 3L, 
1L, 4L, 1L, 2L, 4L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 2L,
3L, 3L, 3L, 3L), .Label = c("54", "55", "61", "69"), class = "factor"),
date = structure(c(16687, 16687, 16687, 16687, 16687, 16687,
16688, 16688, 16688, 16689, 16689, 16690, 16693, 16693, 16693,
16694, 16694, 16695, 16695, 16695, 16695, 16696, 16696, 16696,
16696, 16696, 16696), class = "Date"), facet = c("A",
"A", "A", "A", "A", "B",
"B", "A", "B", "B", "B", "B",
"B", "B", "B", "B", "A", "B",
"A", "B", "A", "C", "B", "C",
"C", "B", "C")), class = "data.frame", row.names = c(NA,
-27L), .Names = c("color", "date", "facet"))

下表总结了每个方面/颜色的观察次数

df.plot %>% group_by(facet, color) %>% summarise(n())

---------------------
facet color n()
------- ------- -----
A 54 5
A 55 2
A 61 2
B 54 6
B 55 3
B 61 2
B 69 3
C 61 4
---------------------

ggplot 生成此图:

ggplot(df.plot, aes(x=date, fill=color)) + 
geom_dotplot(binwidth=1) +
coord_fixed(ratio=1) +
ylim(0,7) +
facet_grid(facet ~ .)

enter image description here

为什么点数有误?例如,我希望 A 54 有 5 分,而绘图只显示 4。

最佳答案

不同颜色但相同日期的点重叠。添加 stackgroups=TRUE 应该会得到预期的结果:

ggplot(df.plot, aes(x=date, fill=color)) + 
geom_dotplot(binwidth=1, stackgroups=TRUE) +
coord_fixed(ratio=1) +
ylim(0,7) +
facet_grid(facet ~ .)

enter image description here

关于r - geom_dotplot 的点数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36178379/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com