Pontifications

  • To plot geom_density() using the colours from your data instead of R's colour palettes you need a named colour vector (see A: in the code below) as well as a mapping in your geom i.e. geom_density() for aes colour (see B:) and scale_colour_manual() (see C:). Not sure why you need the scale_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:

ggplot(singleton_colours_removed_average_colour_ig_van_jan2016_with_colourname, aes(x=colourname))+geom_density(mapping = aes(colour= colour_named_vector))+scale_colour_manual(values=colour_named_vector)

Leave a comment on github