"annotate" in "topright" corner?

6,352 views
Skip to first unread message

Johannes Graumann

unread,
Jun 28, 2010, 11:09:03 AM6/28/10
to ggplot2
Hi,

Is there any easy way of placing text by "annotate" in the top-right
corner (e.g.). I can't find access to the actually used par()$usr
equivalents for a facet ...

Thanks, Joh

Hadley Wickham

unread,
Jun 28, 2010, 12:48:46 PM6/28/10
to Johannes Graumann, ggplot2
Hi Johannes,

If you want the absolute top-right, you can use x = Inf and y = Inf.
If you want slightly off the top-right I don't have any good
suggestions, except to manually compute the limits of each panel
(which is actually pretty easy with ddply)

Hadley

> --
> 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
>

--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

Johannes Graumann

unread,
Jun 28, 2010, 4:13:05 PM6/28/10
to ggplot2
Hi again,

This clearly isn't my day ...

myMovies <- movies
levels(myMovies[["mpaa"]]) <- factor(c("","NC==17","PG","PG==13","R"))
m <- ggplot(myMovies, aes(x=rating))
m + geom_density(aes_string(fill="mpaa",parse=TRUE),alpha=0.2) +
annotate("text",x=Inf,y=Inf,label="Test")

Gives me

Error in data.frame(..., check.names = FALSE) :
arguments imply differing number of rows: 0, 1
Calls: print ... FUN -> lapply -> FUN -> cbind -> cbind -> data.frame

Thanks for any pointers,

Joh

fernando

unread,
Jun 28, 2010, 7:12:02 PM6/28/10
to Johannes Graumann, ggplot2
Hi Johannes,

This works, although I do not understand it very well (e.g. the 'global'
fill is necessary in order to see the text ¿?)

Hope this helps,
fernando


library(ggplot2)

labs <- expression( , NC==17, PG, PG==13, R)
ggplot(data = movies, aes(x = rating, fill = NA)) +
geom_density(alpha = I(0.2), aes_string(fill = "mpaa")) +
scale_fill_discrete(name = "mpaa", breaks = levels(movies$mpaa),
labels = labs, formatter = parse) +
geom_text(x = Inf, y = Inf, label = "Test", hjust = 1, vjust = 1)

-----Mensaje original-----
De: ggp...@googlegroups.com [mailto:ggp...@googlegroups.com] En nombre de
Johannes Graumann
Enviado el: lunes, 28 de junio de 2010 22:13
Para: ggplot2
Asunto: Re: "annotate" in "topright" corner?

Hadley Wickham

unread,
Jul 3, 2010, 9:15:05 AM7/3/10
to fernando, Johannes Graumann, ggplot2
> This works, although I do not understand it very well (e.g. the 'global'
> fill is necessary in order to see the text ¿?)

Me neither - I've open a bug report:
http://github.com/hadley/ggplot2/issues/issue/120

Hadley

Reply all
Reply to author
Forward
0 new messages