add greek letters to the linetype argument

42 views
Skip to first unread message

Chandler

unread,
Sep 27, 2011, 3:00:22 PM9/27/11
to ggp...@googlegroups.com
Hey Guys,

I would like to add Greek letters to the linetype argument.  Here is a simple example:

data <- data.frame(x=1:10,y=1:10,z=11:20)
plot <- ggplot(data,aes(x=x)) + geom_line(aes(y=y,linetype="Greek letters here")) +
    geom_line(aes(y=z,linetype="Greek letters here also"))
plot

I need to be able to mix Greek letters with normal text inside the linetype argument. 

Thanks for the help,

Chandler

Chandler Lutz

unread,
Sep 27, 2011, 2:58:18 PM9/27/11
to ggp...@googlegroups.com

Hadley Wickham

unread,
Sep 27, 2011, 3:13:02 PM9/27/11
to Chandler Lutz, ggp...@googlegroups.com
Could you please explain what Greek letters mean in the context of a line type??

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/

Chandler

unread,
Sep 27, 2011, 3:27:35 PM9/27/11
to ggp...@googlegroups.com, Chandler Lutz
Hi Hadley,

I'm referring to the legend.  I would like to be able allow the description of each line in the legend to include Greek letters.

-Chandler

Chandler

unread,
Sep 28, 2011, 7:57:25 AM9/28/11
to ggp...@googlegroups.com, Chandler Lutz
Hi Hadley,

Let me clarify further.  When I specify the linetype, the text in the linetype goes into the legend.  So, if I have 

plot + geom_line(aes(y=line1,linetype="line1")) + geom_line(aes(y=line2,linetype="line2"))

then "line1" and "line2" will show up in legend describing the two lines.  I need to add Greek letters to the descriptions in the legend of line1 and line2.

I hope this is more clear,

Chandler

Kohske Takahashi

unread,
Sep 28, 2011, 8:13:07 AM9/28/11
to ggp...@googlegroups.com, Chandler Lutz
Hi

try this:

data2 <- melt(data, id = "x")
ggplot(data2, aes(x, value, linetype = variable)) + geom_line() +
scale_linetype("title of legend", breaks = c("y", "z"), labels =
list(expression(alpha), expression(beta)))

--
Kohske Takahashi <takahash...@gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html

Reply all
Reply to author
Forward
0 new messages