[R] ggplot2-geom_text()

Paul Murrell p.murrell at auckland.ac.nz
Mon Mar 30 23:46:01 CEST 2009


Hi


Felipe Carrillo wrote:
> Hi: I need help with geom_text().
>  I would like to count the number of Locations
>  and put the sum of it right above each bar.
> 
> x <- "Location Lake_dens Fish Pred
> Lake1		1.132	1	0.115
> Lake1		0.627	1	0.148
> Lake1		1.324	1	0.104
> Lake1		1.265	1	0.107
> Lake2		1.074	0	0.096
> Lake2		0.851	0	0.108
> Lake2		1.098	0	0.095
> Lake2		0.418	0	0.135
> Lake2		1.256	1	0.088
> Lake2		0.554	1	0.126
> Lake2		1.247	1	0.088
> Lake2		0.794	1	0.112
> Lake2		0.181	0	0.152
> Lake3		1.694	0	0.001
> Lake3		1.018	0	0.001
> Lake3		2.88	0	0"
> DF <- read.table(textConnection(x), header = TRUE)
>  p <- ggplot(DF,aes(x=Location)) + geom_bar()
>  p + geom_text(aes(y=Location),label=sum(count)) # Error because count doesn't exist in dataset
> 
>  What should I use instead of 'count' to be able to sum the number
>  of Locations?


How about ... ?

 p + geom_text(aes(label=..count..), stat="bin",
               vjust=1, colour="white")

Paul


> Felipe D. Carrillo  
> Supervisory Fishery Biologist  
> Department of the Interior  
> US Fish & Wildlife Service  
> California, USA
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
paul at stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/




More information about the R-help mailing list