Expression in labels howto?

8 views
Skip to first unread message

Johannes Graumann

unread,
Jun 28, 2010, 12:20:28 PM6/28/10
to ggplot2
Hi,

when doing something like this

> geom_density(aes(x=tmpResults[[PrecisionColumnName]],fill = tmpResults[["Label"]]),alpha=0.2)

where

> levels(tmpResults[["Label"]])
[1] "Xcalibur, Top 10, HCD; Median==0.11" "COM, Top 2, 3 SIM;
Median==0.04

How can I get the "==" to be parsed expression/plotmath like in the
legend labels?

Thanks, Joh

Hadley Wickham

unread,
Jun 28, 2010, 12:51:09 PM6/28/10
to Johannes Graumann, ggplot2
Hi Johannes,

Try aes_string:

geom_density(aes_string(PrecisionColumnName, fill = "Label"), alpha = 0.2)

I assume this is part of a function or loop, where PrecisionColumnName
is a string that gives the name of the variable you want to plot.

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, 3:49:59 PM6/28/10
to ggplot2
Hi Hadley,

Yes, your assumptions were right ... thanks for the "aes_string" bit
(book is ordered).

It's still not working though - this time I send a minimal example ...

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"),alpha=0.2)

The "=="s remain just that ... how to get them parsed?

Joh
Reply all
Reply to author
Forward
0 new messages