What I have is a dataset with groups within different groups like this below
Year Status Group N
1992 Pre Blue 7
1993 Pre Blue 2
1995 Pre Blue 11
2002 Pre Blue 10
2003 Pre Blue 8
2006 Post Green 7
2007 Post Green 14
2008 Post Green 13
2009 Post Green 9
2010 Post Green 7
2011 Pre Blue 3
2011 Post Green 2
2012 Pre Blue 2
2012 Post Green 4
2013 Pre Blue 5
2013 Post Green 2
2014 Pre Blue 4
2014 Post Green 10
2015 Current Blue 12
2015 Post Green 8
2016 Current Blue 3
2016 Post Green 5
2017 Current Blue 13
2017 Post Green 6
2018 Pre Blue 2
2018 Post Green 7
2019 Pre Blue 9
2019 Post Green 7
What I am trying to do is plot the count(column N) on Y axis, Year on x axis by Group.
- histogram from group Blue to be colored Blue,
- histogram from group Green to be colored
- Grey when Status=Pre,
- Green When Status=Current.
- Yellow when Status = Post
- Add a label showing count on top of each bar of the histogram.
Something like this below [please note the colors in this example below does not match the additional requirements mentioned above].
I am able to plot this using geom_bar but not sure how to plot this various counts by group as a histogram any help is much appreciated.
ggplot(df, aes(Year, N)) +
geom_bar(aes(fill=Group), position="dodge", stat="identity", width=.5)+
geom_text(aes(label=N, group=Group), position=position_dodge(width=0.5), vadjust=-0.5)+
theme_bw(base_size=18)+
ylab('Bedbugs') + xlab('Year')