arf-neuro
arf-neuro

Reputation: 25

ggplot poinstrange with multiple categories - change fill color

I have the following plot:

    ggplot() + 
  geom_pointrange(data=data_FA, mapping=aes(x=snr, y=median, ymin=p25, ymax=p75, colour=factor(method), group=method), position = pd) +
  geom_hline(yintercept=FA_GT, linetype="dashed", color = "blue") +
  theme(legend.title = element_blank(), legend.position = "none", panel.border = element_rect(colour = "gray", fill=NA, size=1),
        plot.margin = unit( c(0,0.5,0,0) , units = "lines" )) +
  labs( title = "", subtitle = "") 

enter image description here

obtained from the following dataset: enter image description here

For each group (red and blue) codified by the factor method, I want to see red/blue dots and lines with different transparency according to the factor subset. Does anyone know how to do that? In addition, how can I add more separation space between the two groups (red and blue)? Thank you!

Upvotes: 0

Views: 193

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173888

You can just map alpha to subset inside aes:

ggplot(data_FA) + 
  geom_pointrange(aes(snr, median, ymin = p25, ymax = p75, 
                      colour = factor(method), group = method,
                      alpha = subset), 
                  position = pd) +
  geom_hline(yintercept = FA_GT, linetype = "dashed", color = "blue") +
  scale_alpha_manual(values = c(0.3, 1)) +
  theme_bw() +
  theme(legend.position = 'none',
        panel.border = element_rect(colour = "gray", fill = NA, size = 1),
        plot.margin  = unit( c(0,0.5,0,0), units = "lines" )) +
  labs(title = "", subtitle = "") 

enter image description here


Data

data_FA <- data.frame(X = c("X1", "X1.7", "X1.14", "X1.21"),
           snr = "snr10",
           subset = c("full", "full", "subset5", "subset5"),
           method= c("sc", "trunc", "sc", "trunc"),
           median = c(0.4883985, 0.4883985, 0.4923685, 0.4914260),
           p25 = c(0.4170183, 0.4170183, 0.4180174, 0.4187472),
           p75 = c(0.5617713, 0.5617713, 0.5654203, 0.5661565))

FA_GT   <- 0.513
pd      <- position_dodge2(width = 1)

Upvotes: 1

Related Questions