print ggplot2 summary on graphic

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

print ggplot2 summary on graphic

Felipe Carrillo
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?

______________________________________________
[hidden email] 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.