我想用图例Episode的值给图中的点加上颜色。我错过了什么?

我用color替换了fill仍然不是我想要的情节

示例代码:
(p <- ggplot(df, aes(x=Type, y=Value, fill=Episode, group=Type)) +
geom_boxplot()+
geom_line()+
geom_dotplot(binaxis='y', stackdir='center',
position=position_dodge(0.8))+
theme_bw())示例数据:
df<-structure(list(Type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L,
7L, 7L, 7L), .Label = c("A", "B", "C", "D", "E", "F", "G"), class = "factor"),
Episode = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L,
1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L,
4L, 5L, 6L), .Label = c("t1", "t2", "t3", "t4", "t5", "t6"
), class = "factor"), Value = c(32, 36, 57, 83, 88, 40, 40,
44, 67, 77, 66, 45, 88, 46, 56, 99, 65, 0, 66, 46, 59, 77,
74, 79, 38, 45, 60, 78, 66, 75, 45, 55, 68, 77, 88, 35, 36,
118, 80, 73, 71, 0)), row.names = c(NA, -42L), class = "data.frame")发布于 2021-04-15 15:39:32
我不能完全确定我是否正确理解了你的问题,但对我来说,最清晰的情节是:
library(ggplot2)
df<-structure(list(Type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L,
7L, 7L, 7L), .Label = c("A", "B", "C", "D", "E", "F", "G"), class = "factor"),
Episode = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L,
4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L,
1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L,
4L, 5L, 6L), .Label = c("t1", "t2", "t3", "t4", "t5", "t6"
), class = "factor"), Value = c(32, 36, 57, 83, 88, 40, 40,
44, 67, 77, 66, 45, 88, 46, 56, 99, 65, 0, 66, 46, 59, 77,
74, 79, 38, 45, 60, 78, 66, 75, 45, 55, 68, 77, 88, 35, 36,
118, 80, 73, 71, 0)), row.names = c(NA, -42L), class = "data.frame")
p <- ggplot(df, aes(x=Type, y=Value, group = Type)) +
geom_boxplot() +
geom_line() +
geom_point(aes(col=Episode))
p

由reprex包创建于2021-04-15 (v0.3.0)
https://stackoverflow.com/questions/67103909
复制相似问题