[R] Adding annotations to qplot from a data frame
Euan Reavie
euan.reavie at gmail.com
Fri Sep 14 04:04:52 CEST 2012
I have the following data frame:
> algaedata =
year DIV cellsperml
2001 BAC 72.808
2001 CHL 3.273
2002 BAC 14.002
2002 CYA 220.896
2002 UNI 464.699
2003 BAP 0
2003 BAC 1.782
2004 CYA 315.799
2005 UNI 222.532
2005 BAP 0.2
2005 CYA 163.627
2005 BAC 324.949
2006 CHL 1.636
2006 BAC 199.145
2007 CHL 19.635
2007 CYA 134.174
2007 BAC 485.405
2007 CHL 11.454
2007 CYA 104.721
...which makes a fine stacked bar plot using:
> qplot(year, data=algaedata, binwidth=1, weight=cellsperml, fill = DIV)
Now I want to annotate along the X-axis with the text "numb" from the
following data frame:
> labelstouse =
x y numb
2001 0 45
2002 0 77
2003 0 2
2004 0 44
2005 0 98
2006 0 55
2007 0 1
For instance, the following did not work:
> qplot(year, data=algaedata, binwidth=1, weight=cellsperml,fill = DIV) +
> grid.text(x = labelstouse$x, y = labelstouse$y, label = labelstouse$numb)
I get the error "Don't know how to add o to a plot." I also attempted
to use multiple configurations of annotate (which only allows one
label) and geom_text but the latter seems to be better suited for
ggplot. Any help would be appreciated in getting these annotations to
work with qplot.
Best - Euan Reavie. U. Minnesota.
More information about the R-help
mailing list