[R] print ggplot2 summary on graphic

Felipe Carrillo mazatlanmexico at yahoo.com
Fri Dec 28 23:32:39 CET 2007


Hi all: The code below works well to print annotations
on base graphics but I can't make it work using the
ggplot2 package. I tried to use the capture.output
function but only prints the summary on the R console
and no on the graphic. Any ideas on how to print
output on ggplot2 graphs? For a powerpoint
presentation I basically just want to show viewers the
mean and Median on the graph since they won't be
seeing the data or the R console.
aa <- 1:10
plot(aa)
text(c(2,4),10, labels=c( "mean", "sd"),col=2)
text(c(2,4),9.5, labels=c(mean(aa), sd(aa)),col=4)
legend("topright",capture.output(sd(aa[1:2])))

m <- ggplot(movies, aes(x=rating))
m + geom_density()
capture.output(mean(movies[3]))


Felipe D. Carrillo
  Fishery Biologist
  US Fish & Wildlife Service
  California, USA



      ____________________________________________________________________________________
Looking for last minute shopping deals?



More information about the R-help mailing list