首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Boxplot颜色不匹配

Boxplot颜色不匹配
EN

Stack Overflow用户
提问于 2021-04-15 15:17:48
回答 1查看 17关注 0票数 0

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

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

示例代码:

代码语言:javascript
复制
(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())

示例数据:

代码语言:javascript
复制
 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")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-15 15:39:32

我不能完全确定我是否正确理解了你的问题,但对我来说,最清晰的情节是:

代码语言:javascript
复制
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)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67103909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档