including color and linetype in ggplot legend

82 views
Skip to first unread message

godwin

unread,
Mar 2, 2012, 1:09:17 AM3/2/12
to ggplot2
Hi all,

I have the following data.frame:

n model beta power
1 50 1 1 0.6294
2 50 2 1 0.6293
3 50 3 1 0.5061
4 75 1 1 0.8022
5 75 2 1 0.7873
6 75 3 1 0.6796
7 100 1 1 0.9020
8 100 2 1 0.8878
9 100 3 1 0.8029
19 50 1 2 0.3128
20 50 2 2 0.1054
21 50 3 2 0.2035
22 75 1 2 0.4208
23 75 2 2 0.1275
24 75 3 2 0.2705

I wish to plot n vs model, color according to model, and set linetype
to beta. I've managed to do so with the following code, but am having
trouble changing the linetype in the legend. Any ideas?

qplot(n, power, col=factor(4*model+beta), lty=beta, data=result,
geom="line") + theme_bw() + scale_colour_manual(values=c("#999999",
"#999999", "#E69F00", "#E69F00", "#56B4E9", "#56B4E9"), name="Legend",
breaks=c(5,6,9,10,13,14), labels=c("m1,b1", "m1,b2", "m2,b1", "m2,b2",
"m3,b1", "m3,b2"))

Best,
Godwin

Ben Bond-Lamberty

unread,
Mar 2, 2012, 5:27:22 AM3/2/12
to ggplot2
Use lty=as.factor(beta)

Ben

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

Reply all
Reply to author
Forward
0 new messages