I see two options. You can either manually specify the linetype for
each level of your factor, OR you can reorder your factor to match
your desired line types (obviously somewhat less flexible, but can be
easier code wise). Example code follows.
Cheers,
Josh
library(ggplot2)
## data
dat <- data.frame(x=1:10, y=1:10,
group = factor(rep(letters[1:5], each = 2)))
## default lines
ggplot(data = dat, aes(x = x, y = y, linetype = group)) +
geom_line()
## manually set liens
ggplot(data = dat, aes(x = x, y = y, linetype = group)) +
geom_line() +
scale_linetype_manual(name = "Linetype",
value = c("a" = 2, "b" = 3, "c" = 4, "d" = 1, "e" = 5))
## reorder factor so non-alphabetical
dat$group <- factor(dat$group, levels = c("d", "a", "b", "c", "e"))
## new default lines
ggplot(data = dat, aes(x = x, y = y, linetype = group)) + geom_line()
> --
> 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
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/
I just sort of assumed you were using a factor, I guess. AFAIK things
like the scale training and mapping is done using factors for discrete
data. When factor() is called on data, the levels are, by default,
alphabetical, but if you have already created factor class data and
specified a different ordering for levels than those will be kept.
The linetype and legend order are, again AFAIK, determined by the
levels of the factor.
Take that with some caution though, I have not actually watched all
the different steps between the call and the final graph.
HTH,
Josh