I am producing figures of effect sizes and associated confidence intervals such as this:
using ggplot2's geom_pointrange. I would like for the second point-line to be transparent but for the transparency not to be additive (i.e. just be one solid color rather than showing up as a darker line through the point).
I apply the custom colors with:
+ scale_colour_manual(values=c("#66CD0050","#66CD00"))
Thank you for any suggestions.
The comment from thelatemail is spot on for this question. Using the scale_color_manual
call to define the colors will generate the image requested. See the example below.
library(ggplot2)
dat <- data.frame(effect_size = c(-0.1, -0.1),
lcl = c(-0.5, -0.2),
ucl = c(0.3, -0.01),
sla = c("SLA1", "SLA2"))
ggplot(dat) +
theme_classic() +
aes(x = sla, y = effect_size, ymin = lcl, ymax = ucl, color = sla) +
geom_pointrange() +
geom_hline(yintercept = 0, linetype = 2) +
scale_color_manual(values = c("SLA1" = "#66CD00",
"SLA2" = "#cfefb0")) +
coord_flip()
packageVersion("ggplot2")
# [1] ‘2.2.1.9000’
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With