代码之家  ›  专栏  ›  技术社区  ›  DXL

如何更改箱线图中的填充颜色

  •  -2
  • DXL  · 技术社区  · 8 年前

    我想用下面的代码更改箱线图中的填充颜色,但代码颜色只更改边框的颜色。

    p = ggplot(data=concentration,aes(factor(status), con), ylim=c(0,0.15),cex.axis=1.5,cex.lab=15) + 
    stat_summary(fun.data=f, geom="boxplot", position="dodge",color='blue') + 
    ylab(expression(paste("Formaldehyde concentration"," (",mu,"g/",m^3,")"))) +
    xlab("") + 
    ylim(0,200) #+ 
    geom_boxplot(aes(fill = Condition))
    

    如何更改填充颜色?

    1 回复  |  直到 8 年前
        1
  •  1
  •   Michael Harper    8 年前

    您可以在此处看到编辑ggplot箱线图美学的所有方法: http://ggplot2.tidyverse.org/reference/geom_boxplot.html

    • 阿尔法
    • 颜色
    • 填满
    • 线型
    • 形状
    • 大小
    • 重量

    在您的情况下,您希望更改填充:

    set.seed(123)
    concentration <- data.frame(status = c("Yes", "No"), con = rnorm(n = 30) + 10)
    
    ggplot(data=concentration, aes(factor(status), con)) + 
    geom_boxplot(fill = "blue")
    

    enter image description here