To plot geom_density() using the colours from your data you need a colour vector and scale_colour_manual
Pontifications
- To plot
geom_density()
using the colours from your data instead of R’s colour palettes you need a named colour vector (seeA:
in the code below) as well as a mapping in your geom i.e.geom_density()
foraes
colour (seeB:
) andscale_colour_manual()
(seeC:
). Not sure why you need thescale_colour_manual()
to be honest!
Here’s the code:
# A:
# Don't need as.character() since it's already a character
colour_named_vector <- setNames
(singleton_colours_removed_average_colour_ig_van_jan2016_with_colourname$colourname, singleton_colours_removed_average_colour_ig_van_jan2016_with_colourname$colourname)
ggplot(
singleton_colours_removed_average_colour_ig_van_jan2016_with_colourname,
aes(x=colourname))+
geom_density(mapping = aes(colour= colour_named_vector))+ # B:
scale_colour_manual(values=colour_named_vector) #C:
Output: