如何控制ggplot小提琴情节中的透明度(alpha)(点)

时间:2016-02-03 01:38:59

标签: r ggplot2

以下图片

enter image description here

使用以下代码创建:

library(ggplot2)
library(plyr)
library(reshape)

df<- structure(list(variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "bCD.ID.LN", class = "factor"),
    value = c(1.133, 1.068, 1.01, 0.943, 1.048, 1.053, 0.999,
    1.014, 1.149, 1.068, 0.898, 1.008, 0.976, 1.029, 0.95, 0.986,
    1.102, 1.007, 1.08, 1.219), fc_log = c(0.180147861158429,
    0.094911647025467, 0.0143552929770701, -0.0846703239869906,
    0.0676387168753633, 0.0745054363636298, -0.00144341686966872,
    0.0200576523412535, 0.200378797984026, 0.094911647025467,
    -0.15521264992094, 0.0114956388378294, -0.0350469470992008,
    0.0412429822318813, -0.0740005814437769, -0.0203404482841755,
    0.140124223909071, 0.0100636833446975, 0.111031312388744,
    0.285698125958125), len = c(26654L, 26654L, 26654L, 26654L,
    26654L, 26654L, 26654L, 26654L, 26654L, 26654L, 26654L, 26654L,
    26654L, 26654L, 26654L, 26654L, 26654L, 26654L, 26654L, 26654L
    ), ecd = c(0.77027838223156, 0.633263300067532, 0.462219554288287,
    0.290425452089743, 0.577361746829744, 0.592744053425377,
    0.431417423276056, 0.473737525324529, 0.791888647107376,
    0.633263300067532, 0.203909356944549, 0.456929541532228,
    0.367524574172732, 0.519246642155024, 0.3059953477902, 0.395137690402941,
    0.713251294364823, 0.453365348540557, 0.663840324153973,
    0.865123433630975)), .Names = c("variable", "value", "fc_log",
"len", "ecd"), row.names = c(NA, 20L), class = "data.frame")


   ggplot(df, aes(x = factor(variable), y=fc_log)) +
    geom_violin(adjust=.5, trim=FALSE, fill='#A4A4A4', color="darkred" ) +
    geom_boxplot(width=0.1) + theme_minimal() +
    ylab("log2(fold change)") +
    xlab("")

如图所示,如何使点透明?

1 个答案:

答案 0 :(得分:2)

Use the outlier.colour= for geom_boxplot with rgb and a transparency argument ('alpha'):

geom_boxplot(width=0.1, outlier.colour=rgb(.5,.5,.5, 0.5) ) + theme_minimal() +