Adding text to a plot (geom_pointrange)

85 views
Skip to first unread message

Manuel Spínola

unread,
Oct 17, 2010, 12:47:00 PM10/17/10
to ggplot2
Dear list members,

I want to add an "a" in the corner of a plot using geom_text but with geom_pointrange, but I don't know how to set the position (the x axis is categorical):

dfa = data.frame(a = factor(c("18-25 años", "26-35 años", "36-45 años", "46-60 años", ">60 años"), levels=c("18-25 años", "26-35 años", "36-45 años", "46-60 años", ">60 años")), b = c(16, 42, 17, 20, 4))

limitesa <- aes(ymax =c(25, 53, 26, 29, 10) , ymin=c(0.9, 32, 10, 12, 1))

a = ggplot(dfa, aes(y=b, x=a)) + geom_pointrange(limitesa, size = 1) + xlab("Categoría de Edad") + ylab("Porcentaje (%)") + opts(legend.position = "none") + theme_bw() + geom_text(aes(a, b, label = "a"))

Thank you very much in advance.
Best,

Manuel

--
Manuel Spínola, Ph.D.
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspi...@una.ac.cr
mspin...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río
Institutional website: ICOMVIS

Felipe Carrillo

unread,
Oct 17, 2010, 1:18:14 PM10/17/10
to Manuel Spínola, ggplot2
Manuel:
If you just want to add text, 'annotate' is probably the way to go:
 
dfa = data.frame(a = factor(c("18-25 años", "26-35 años", "36-45 años", "46-60 años", ">60 años"), levels=c("18-25 años", "26-35 años", "36-45 años", "46-60 años", ">60 años")), b = c(16, 42, 17, 20, 4))
limitesa <- aes(ymax =c(25, 53, 26, 29, 10) , ymin=c(0.9, 32, 10, 12, 1))
a = ggplot(dfa, aes(y=b, x=a)) + geom_pointrange(limitesa, size = 1) + xlab("Categoría de Edad") + ylab("Porcentaje (%)") + opts(legend.position = "none") + theme_bw()
a
a
a + annotate("text",x=0,y=55,label="a")
 
Felipe D. Carrillo
Supervisory Fishery Biologist
Department of the Interior
US Fish & Wildlife Service
California, USA


--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: http://gist.github.com/270442
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Reply all
Reply to author
Forward
0 new messages