Simplest ggplot2 Bar Chart using colours as bar values

Jul 31, 2016

Things to note:

It doesn't seem to matter what you use for x in the aes statement , x=color, x=factor(1) both work

In aes(x=colour, fill=I(colour)) if you use fill=I(colour) i.e. use the literal colour values to colour the bar chart, then no legend is produced by ggplot2. If you need a legend, then use fill=colour in the AES to force a legend and add scale_fill_manual() to make a legend with the colours you want (see blog post on how to make literal colour pie charts with a legend). Not sure if this is a bug in ggplot2 or if there is an option to force a legend when using literal colour values.

In p= p + geom_bar(stat="count") you need stat="count if you want ggplot to count the number of occurrences (in this case AFAICT all colours only appear once for most instagram vancouver vancouver 2016 photos for any particular hour!), i.e. your data is un-summarized. If your data is summarized then you can use stat="identity"