[R] ggplot2 lost label

Troels Ring tring at gvdnet.dk
Sun Sep 18 20:05:27 CEST 2016

dear friends - I have a problem in ggplot2 which I hope you can help me 
understand and solve.

Running windows 7, R 3.2.1

grp <- gl(3,4,12)
trt <- gl(4,1,12)
num <- c(11,1,0,0,6,2,0,0,1,9,10,10)
MM <- data.frame(grp=grp,num=num,trt=trt)
levels(MM$grp)<- c("anest1","anest2","anest3")
levels(MM$trt)<- c("drug1","drug2","drug3","drug4")

geom_bar(mapping=aes(x=grp,y=num),fill=trt,stat="identity") +
theme(legend.position="top") + ylab("Number")+xlab("")

How do Imake ggplot make a label? - I tried to 
annotate("text",1,5,"drug1") returning

mapping: x = x, xmin = xmin, y = y
geom_text: na.rm = FALSE
stat_identity: na.rm = FALSE

so that was not as I thought. How do I get the label directly - or 
annotate if that is the only possibility?

Best wishes

Troels Ring

More information about the R-help mailing list