geom_smooth and linetype: legend doesn't show different linetypes

783 views
Skip to first unread message

Bernd Weiss

unread,
Jul 14, 2009, 7:28:06 AM7/14/09
to ggplot2
Dear all,

how can I 'force' ggplot2 to plot different linetypes in the legend?

library(ggplot2)

x <- rnorm(100)
y <- rnorm(100)
g <- as.factor(rep(1:4, 25))

mydata <- data.frame(x,y,g)

## version 1
ggplot(aes(x = x, y = y, linetype = g), data = mydata) + geom_smooth
(method = "lm")
## version 2
ggplot(aes(x = x, y = y), data = mydata) + geom_smooth(aes(linetype =
g), method = "lm")


I guess I have to apply one of the scales-functions...

Thanks for your help,

Bernd

hadley wickham

unread,
Jul 14, 2009, 7:40:46 AM7/14/09
to Bernd Weiss, ggplot2
What's the problem? Both of those examples show varying line types for me.

Hadley
--
http://had.co.nz/

Bernd

unread,
Jul 14, 2009, 7:51:49 AM7/14/09
to ggplot2
On 14 Jul., 13:40, hadley wickham <h.wick...@gmail.com> wrote:
> What's the problem?  Both of those examples show varying line types for me.

Sorry, you are absolutely right. It seems to be a problem with R's
graphic device.

If I create a PDF file, everything works fine: http://metaanalyse.de/tmp/figPDF.pdf

I also made a screenshot which should demonstrate my problem:
http://metaanalyse.de/tmp/figScreen.png (left-hand side)


Thanks for your quick reply,

Bernd


P.S.: My sessionInfo()

> sessionInfo()
R version 2.9.1 Patched (2009-07-04 r48899)
i386-pc-mingw32

locale:
LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.
1252;LC_MONETARY=German_Germany.
1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252

attached base packages:
[1] grid stats graphics grDevices utils datasets
methods
[8] base

other attached packages:
[1] ggplot2_0.8.3 reshape_0.8.3 plyr_0.1.9 proto_0.3-8

loaded via a namespace (and not attached):
[1] tools_2.9.1

hadley wickham

unread,
Jul 20, 2009, 8:54:55 AM7/20/09
to Bernd, ggplot2
On Tue, Jul 14, 2009 at 6:51 AM, Bernd<sp...@metaanalyse.de> wrote:
>
> On 14 Jul., 13:40, hadley wickham <h.wick...@gmail.com> wrote:
>> What's the problem?  Both of those examples show varying line types for me.
>
> Sorry, you are absolutely right. It seems to be a problem with R's
> graphic device.

Unfortunately there's not much I can do about it in this case. If you
can create a very simple self-contained example, you might try posting
it to R-help.

Hadley


--
http://had.co.nz/

Reply all
Reply to author
Forward
0 new messages