Using ggplot2, I would like annotate my faceted geom_pont plots : I am plotting some data per plant for 2 parameters and I would like to annotate each faceted plots with the population size of each plant which make the plot. Below is a similar example to my data.
Lets subset the CO2
dataset to make the example more relevant. I count the number of plant for which the uptake is above 20 and rename the column:
require(plyr)
require(dplyr)
require(ggplot2)
CO2_mod<-subset(CO2,uptake>20)
COUNT<-ddply(.data=CO2_mod,
.variable=.(Plant,Treatment),
.fun=count)
names(COUNT)[3] <- c("PopSize")
Here is the code for faceted plots based on treatments:
p1<-ggplot(CO2_mod, aes(x=Plant, y=uptake))
p2<-p1+geom_point(aes())+
facet_grid(Treatment~., scales="free")
p2
Now I would like to annotate each faceted plot with the PopSize
value per Plant
and per Treatment
from the COUNT
df.
I have tried this code without success:
y<-max(CO2_mod$uptake)+1
COUNT<-mutate(COUNT,y=paste0(y))
p2<-p1+geom_point(aes())+
facet_grid(Treatment~., scales="free")+
geom_text(data=COUNT, aes(x=Plant, y=y, label=PopSize),
colour="black")
p2
The error warning says : Error: Discrete value supplied to continuous scale
What would be the right way to do this? thanks!