Data group goes missing with linetype

2 views
Skip to first unread message

Marc Liberatore

unread,
Mar 23, 2009, 11:27:56 AM3/23/09
to ggplot2
I love the ideas behind ggplot2. It being new to me, I sometimes run
into trouble. For example:

Help! My groups are going missing!

I have a data set with 5 groups of data. When I map groups to a
colour, ggplot2 does what I'd expect. When I map groups to a
linetype, the one of my groups goes missing. Is there an inbuilt
limit to the number of linetypes, or is something else going on? If
it's the latter, I'm surprised the default isn't to go back to a solid
line (as opposed to disappearing the line entirely). Sample code at
the end of this post.

I understand that using linetype alone to distinguish data groups get
bad as the number of groups increases, but I'm working under a black-
and-white constraint. How can I get my linetype back? Alternatively,
can you suggest a way to distinguish the lines? I'm trying to avoid
using points, as they don't appeal to my own aesthetic.

Cheers,
Marc

sample.data

n c circuitlen killprob avgcompprob
100 9 3 0.010000 0.022716
100 9 3 0.050000 0.023203
100 15 3 0.010000 0.065866
100 15 3 0.050000 0.068166
100 21 3 0.010000 0.130784
100 21 3 0.050000 0.137235
100 27 3 0.010000 0.221241
100 27 3 0.050000 0.227822
100 33 3 0.010000 0.332224
100 33 3 0.050000 0.348631

sample.R
library(ggplot2)

orig <- read.table("sample.data", header=TRUE)
sample <- data.frame(killprob=orig$killprob,
avgcompprob=orig$avgcompprob,
c = factor(orig$c))

p <- ggplot(sample, aes(killprob, avgcompprob, group = c))
p <- p + geom_line(aes(colour = c))

pdf("sample-colour.pdf", width=8, height=4)
p
dev.off()


p <- ggplot(sample, aes(killprob, avgcompprob, group = c))
p <- p + geom_line(aes(linetype = c))

pdf("sample-linetype.pdf", width=8, height=4)
p
dev.off()

Marc Liberatore

unread,
Mar 24, 2009, 9:41:45 AM3/24/09
to ggplot2
Ah ha. The vanishing of the line was an artifact of a theme_set
(theme_bw()) from a previous interactive session. My apologies to you
if you spent time on this unnecessarily.

Reply all
Reply to author
Forward
0 new messages