Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove additive transparency in ggplot2 geom_pointrange

I am producing figures of effect sizes and associated confidence intervals such as this:

enter image description here

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.

like image 223
dmarvs Avatar asked Nov 12 '22 22:11

dmarvs


1 Answers

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’

enter image description here

like image 149
Peter Avatar answered Nov 15 '22 13:11

Peter