I am working with a data frame, where I have columns:
species replicate position DOY RED.PEAK RED.PEAK.SD FAR.RED.PEAK FAR.RED.PEAK.SD
1 LINGONBERRY 1 LOW 1 0.10218177 0.050779465 0.14498610 0.04848566
2 LINGONBERRY 1 LOW 10 0.12089622 0.039990500 0.18177440 0.03263417
3 LINGONBERRY 1 LOW 2 0.10861619 0.039823347 0.20582430 0.05709061
4 LINGONBERRY 1 LOW 3 0.05398631 0.006064099 0.10750730 0.01954550
5 LINGONBERRY 1 LOW 4 0.08722205 0.017874483 0.14446139 0.03133565
6 LINGONBERRY 1 LOW 5 0.04872162 0.028601630 0.09535204 0.02216967
Where species, replicate, position and time are my cases, RED.PEAK and FAR.RED.PEAK are my values and RED.PEAK.SD and FAR.RED.PEAK.SD are standard deviations of RED.PEAK and FAR.RED.PEAK.
I am using ggplot to plot different species (3) with facet_grid, different positions (2) with linetype, and different replicates (3) with colors.
NEW.gridplot <- ggplot(new.plot.table,aes(DOY, RED.PEAK, group=interaction(position, replicate)))+
scale_x_discrete(limit = c("II Feb", "I Mar", "II Mar", "I Apr", "II Apr", "I May", "II May", "I Jun", "II Jun", "I Jul"))+
facet_grid(.~species)+
geom_line(aes(color=replicate, linetype=position), size=2)+
scale_linetype_manual(values=c("dashed", "solid")) +
scale_color_manual(values = c('black', 'red', 'blue')) +
geom_ribbon(aes(ymin = RED.PEAK - RED.PEAK.SD,
ymax = RED.PEAK + RED.PEAK.SD), alpha = 0.1) +
myplotting
print(NEW.gridplot)
see an example of ggplot I am having now
and it works well. I would like to, however, colour the shading to black, blue and red in geom_ribbon as well.
geom_ribbon(aes(ymin = RED.PEAK - RED.PEAK.SD,
ymax = RED.PEAK + RED.PEAK.SD), alpha = 0.1, fill=(values = c('black', 'red', 'blue')))
did not work, delivering error Error: Aesthetics must be either length 1 or the same as the data (150): fill Then:
geom_ribbon(aes(ymin = ORANGE.PEAK - ORANGE.PEAK.SD,
ymax = ORANGE.PEAK + ORANGE.PEAK.SD), alpha = 0.1, fill=replicate)+
scale_fill_manual(values = c('black', 'red', 'blue'))
did not work either, delivering error Error in rep(value[[k]], length.out = n) : attempt to replicate an object of type 'closure'
Looking for a solution to have my shadings from geom_ribbon the same colors as their corresponding lines from geom_line.
color
instead offill
? – Duck