0
votes

I created a ggplot with data.frame f:

fe  ci1 median  ci2 obs mode    mode2
s9  0.00283 0.07459 0.336   0   global  global2
s8  0.00273 0.07343 0.3373  0   global  global2
s7  0.00280 0.07435 0.3366  0   global  global2
gc10    0.5163  0.8201  0.9716  0.2 global  global2
gc9 0.2997  0.6065  0.8653  0.4 global  global2
gc8 0.1377  0.3933  0.7015  0   global  global2
gc7 0.0276  0.1806  0.4867  0   global  global2
s9  0.00282 0.07451 0.3348  0   general general2
s8  0.00283 0.07399 0.3376  0   general general2
s7  0.00294 0.07403 0.3382  0   general general2
gc10    0.5171  0.8207  0.9722  0.2 general general2
gc9 0.2998  0.6054  0.8631  0.4 general general2
gc8 0.1361  0.393   0.7001  0   general general2
gc7 0.0275  0.1792  0.4824  0   general general2
s9  0.00634 0.1584  0.6003  1   proximal    proximal2
s8  0.00627 0.159   0.6042  1   proximal    proximal2
s7  0.00638 0.1587  0.6006  0   proximal    proximal2
gc10    0.401   0.8406  0.9936  1   proximal    proximal2
gc9 0.4007  0.8418  0.9937  1   proximal    proximal2
gc8 0.4012  0.8411  0.9936  1   proximal    proximal2
gc7 0.3972  0.8411  0.9937  1   proximal    proximal2

This code produces parallel error bars with the values of variables median and obs as points:

gpf <- ggplot( f, aes(x= fe, y= median, fill= mode), color = mode, group= mode, fill= mode ) +
geom_errorbar(aes(ymin = ci1, ymax = ci2), width = .2, position = pdf, color = aes(mode) ) +
geom_point(position = pdf, aes(shape = mode)) +
geom_vline(xintercept = 17.5, linetype = "longdash") + 
geom_point(position = pdf, aes(x= fe, y= obs, shape = mode2)) +
scale_shape_manual(values=c(15:17, 0:2))
print( gpf + theme_bw() + theme(axis.title.x = element_blank()) + theme(axis.title.y = element_text(face="bold")) )

How can I have hollow points for variable obs and solid ones for variable median (keeping the same shape for each group)? Also, how can I get a unique legend for mode?

Thank you for your help

2

2 Answers

0
votes

I can't run your code as is, but you can have different shapes per variable in geom_point depending on a factor:

geom_point(position = pdf, aes(x= fe, y= obs, shape = factor(mode2)))
0
votes

After quite a bit of prove and error I think I found the answer:

gpf <- ggplot( f, aes(x= fe, y= median, fill= mode), color = mode, group= mode, fill= mode ) +
geom_errorbar(aes(ymin = ci1, ymax = ci2), width = .2, position = pdf, color = aes(mode) ) +
geom_point(position = pdf, aes(shape = mode)) +
geom_vline(xintercept = 17.5, linetype = "longdash") + 
geom_point(position = pdf, aes(x= fe, y= obs, shape = mode2)) +
guides(shape= guide_legend("Mode of\n replacement")) +
scale_shape_identity() +
scale_shape_manual(values=c(16,1, 17,2, 15,0))
print( gpf + theme_bw() + theme(axis.title.x = element_blank()) + theme(axis.title.y = element_text(face="bold")) + guides(fill=FALSE) )