I am venturing babysteps in ggplots and need some help with the following problem!
I have a dataframe called dftemp which has the following structure
Year Month Values
1 1996 Jan 0
2 1996 Feb 0
3 1996 Mar 0
4 1996 Apr 0
5 1996 May 0
6 1996 Jun 0
7 1996 Jul 0
8 1996 Aug 0
9 1996 Sep 0
10 1996 Oct 0
11 1996 Nov 0
12 1996 Dec 0
This goes on like this until:
181 2011 Jan -3
182 2011 Feb 2
183 2011 Mar 2
184 2011 Apr 6
185 2011 May -13
186 2011 Jun -4
187 2011 Jul 0
188 2011 Aug 0
189 2011 Sep 0
190 2011 Oct -7
191 2011 Nov -7
192 2011 Dec 0
I tried to make a barchart by:
ggplot(dftemp,aes(x=Month,y=Values,fill=Year))+geom_bar(binwidth=10)
And got something weird and wrong (sadly my reputation is not high enough so I cannot post the image)..The resulting plot had y-values that were squished together very tightly by the bottom of the y-axis..
I don’t understand what I am doing wrong here! I tried putting factor() in front of the aes inputs but to no avail!
Your first challenge is to use the stat=”identity” argument in your geom_bar
It is not clear what you are trying to plot, or how you plan to combine your data, so I’ll offer a few options.
First let’s rebuild your data for use:
Here is a simple bar plot, one bar for each date stamp:
One bar per month, stacked
One bar per year, stacked