Re: using scale_linetype_manual

3,468 views
Skip to first unread message

Brandon Hurr

unread,
Oct 26, 2012, 2:47:27 PM10/26/12
to stan, ggp...@googlegroups.com
Can you provide more context or a working example? I left my ggplot2 book at work.Ā 

On Fri, Oct 26, 2012 at 6:12 PM, stan <sa...@cdc.gov> wrote:
When use the example on p. 108 of the Wickam "ggplot2" text,Ā  and inlcude the follwoing line:
Ā plotĀ  + aes(linetype=vore) + scale_linetype_manual(value=c(0,1,2,3,4))
Ā 
the output plots no lines.
I must be using the manual function incorrectly.
Ā 
Any suggestions?
Ā 
Ā Ā 

--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
Ā 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

Brandon Hurr

unread,
Oct 26, 2012, 3:02:59 PM10/26/12
to Shulman, Stanley A. (CDC/NIOSH/DART), ggplot2
I mean, can you provide what "plot" is? I can't replicate it without the book unless you tell me what the data is.Ā 

I'm guessing that in plot they are using geom_point(), but there might not be a geom_line(). Ā 

B



On Fri, Oct 26, 2012 at 7:59 PM, Shulman, Stanley A. (CDC/NIOSH/DART) <sa...@cdc.gov> wrote:

Thanks for the reply.

I must be doing something wrong.

Ā 

When I enter the following :

Ā 

plotĀ  + aes(shape=vore) + scale_shape_manual(value=c(1,2,6,0,23))

Ā 

the data are plotted with five different symbols, one for each of five groups.

Ā 

When the change is made from shapes to linetypes,

Ā 

plotĀ  + aes(linetype=vore) + scale_linetype_manual(value=c(0,1,2,3,4))

Ā 

no lines appear.Ā  The values 0,1,2,3,4 are allowed identifiers for different kinds of lines. I am confused.

Ā 

That is my problem.Ā  Any thoughts?

Brandon Hurr

unread,
Oct 26, 2012, 3:49:27 PM10/26/12
to Shulman, Stanley A. (CDC/NIOSH/DART), ggplot2, ggplot2-dev
Yeah... this looks really broken Stanley. I'm guessing bug.Ā 

#redoing this in ggplot() format...
ggplot(data=msleep, aes(x=brainwt, y=bodywt, linetype=factor(vore)), group=vore)+ geom_line()
Error in grid.Call.graphics(L_lines, x$x, x$y, index, x$arrow) :Ā 
Ā  invalid hex digit in 'color' or 'lty'

It actually did plot something and I can see the lines when I change the quartz() window size, but the axes, axes titles, and other parts are all missing. geom_point() does work in the same format.

> levels(msleep$vore)
[1] "carni" Ā  "herbi" Ā  "insecti" "omni" Ā Ā 

Not sure what to tell you... I don't have an answer.Ā 

On Fri, Oct 26, 2012 at 8:29 PM, Shulman, Stanley A. (CDC/NIOSH/DART) <sa...@cdc.gov> wrote:

plot <- qplot(brainwt, bodywt, data=msleep, log=ā€xyā€)

Ā 

does this help?

Winston Chang

unread,
Oct 26, 2012, 4:03:45 PM10/26/12
to Brandon Hurr, Shulman, Stanley A. (CDC/NIOSH/DART), ggplot2
I think it has to do with the NAs in the vore column. This works:

ms <- msleep[ !is.na(msleep$vore), ]
ggplot(data=ms, aes(x=brainwt, y=bodywt, linetype=factor(vore)), group=vore)+ geom_line()

But it is a bug. Could you file an issue on github?

-Winston

Brian Diggs

unread,
Oct 26, 2012, 4:28:12 PM10/26/12
to stan, ggplot2
On 10/26/2012 10:12 AM, stan wrote:
> When use the example on p. 108 of the Wickam "ggplot2" text,

To make this reproducible for those that don't have the book at
hand/memorized:

plot <- qplot(brainwt, bodywt, data=msleep, log="xy")

> and inlcude the follwoing line:
> plot + aes(linetype=vore) + scale_linetype_manual(value=c(0,1,2,3,4))
>
> the output plots no lines.

I get an error:

Error in structure(list(call = match.call(), aesthetics = aesthetics, :
argument "values" is missing, with no default

The argument should be `values`, not `value`

Making that change:

plot + aes(linetype=vore) + scale_linetype_manual(values=c(0,1,2,3,4))

does not have lines. But that has nothing to do with the manual
linetype. The issue is that qplot makes points by default. Points have
shape and colour, but not a linetype. You need to draw lines before you
see the effect of a linetype.

plot + geom_line() + aes(linetype=vore) +
scale_linetype_manual(values=c(1,2,3,4), na.value=0)

> I must be using the manual function incorrectly.
>
> Any suggestions?

--
Brian S. Diggs, PhD
Senior Research Associate, Department of Surgery
Oregon Health & Science University

Shulman, Stanley A. (CDC/NIOSH/DART)

unread,
Oct 29, 2012, 10:04:33 AM10/29/12
to Winston Chang, Brandon Hurr, ggplot2

It happens that I need to put both symbols and lines on the plot, and I need to be able to choose the lines and symbols that are assigned.Ā  I seem to need to use scale_shape_manual and Ā scale_linetype_manual to correctly set the desired symbols and Ā lines, but the following code does not work with regard to the lines.Ā  Any suggestions?

##the following code seems to remove all nas for all variables used, I think. Ā Ā 

ms <- msleep[ !is.na(msleep$vore) & !is.na(msleep$brainwt)Ā  & !is.na(msleep$bodywt),]

q1 <-Ā  qplot(brainwt,bodywt,data=ms)

q2 <- q1 + aes(shape=vore) + scale_shape_manual(value=c(1,2,6,0))

q3 <- q1 + aes(linetype=vore) + scale_linetype_manual(value=c(0,1,2,3))

q4 <- q2 + aes(linetype=vore) + scale_linetype_manual(value=c(0,1,2,3))

Ā 

Also, how do I iissue an github?

Thanks

Winston Chang

unread,
Oct 29, 2012, 2:17:09 PM10/29/12
to Shulman, Stanley A. (CDC/NIOSH/DART), Brandon Hurr, ggplot2
No worries, I just filed it:

-Winston
Reply all
Reply to author
Forward
0 new messages