Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the key thing is that you need to do the frequency calculation outside of ggplot. Use aggregate() with geom_bar(stat="identity") to get a histogram without the reordered factors. Here is some example code:</p> <pre><code>require(ggplot2) # scales goes with ggplot and adds the needed scale* functions require(scales) # need the month() function for the extra plot require(lubridate) # original data #df&lt;-read.csv("http://pastebin.com/download.php?i=sDzXKFxJ", header=TRUE) # simulated data years=sample(seq(2008,2012),681,replace=TRUE,prob=c(0.0176211453744493,0.302496328928047,0.323054331864905,0.237885462555066,0.118942731277533)) months=sample(seq(1,12),681,replace=TRUE) my.dates=as.Date(paste(years,months,01,sep="-")) df=data.frame(YM=strftime(my.dates, format="%Y-%b"),Date=my.dates,Year=years,Month=months) # end simulated data creation # sort the list just to make it pretty. It makes no difference in the final results df=df[do.call(order, df[c("Date")]), ] # add a dummy column for clarity in processing df$Count=1 # compute the frequencies ourselves freqs=aggregate(Count ~ Year + Month, data=df, FUN=length) # rebuild the Date column so that ggplot works freqs$Date=as.Date(paste(freqs$Year,freqs$Month,"01",sep="-")) # I set the breaks for 2 months to reduce clutter g&lt;-ggplot(data=freqs,aes(x=Date,y=Count))+ geom_bar(stat="identity") + scale_x_date(labels=date_format("%Y-%b"),breaks="2 months") + theme_bw() + opts(axis.text.x = theme_text(angle=90)) print(g) # don't overwrite the previous graph dev.new() # just for grins, here is a faceted view by year # Add the Month.name factor to have things work. month() keeps the factor levels in order freqs$Month.name=month(freqs$Date,label=TRUE, abbr=TRUE) g2&lt;-ggplot(data=freqs,aes(x=Month.name,y=Count))+ geom_bar(stat="identity") + facet_grid(Year~.) + theme_bw() print(g2) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload