Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

geom_vline argument linetype does not accept a vector in v0.9.0/R2.14 although it did in v0.8.9/R2.12 #559

Closed
dlebauer opened this Issue · 6 comments

3 participants

@dlebauer

Something like this is in my existing code:

ggplot(data = data.frame(x=1:3,y=1:3)) + 
            geom_point(aes(x,y)) + 
            geom_vline(aes(xintercept = c(0.5, 0.95, 1), linetype = c(2,1,2)), color = 'grey')

It works fine in ggplot v 0.8.9, but in v. 0.9.0, I get the following error:

Error: A continuous variable can not be mapped to linetype

The problem is resolved by changing the code to linetype = as.factor(c(2,1,2))

This change breaks old code, I don't see the value in the change (although perhaps there is value). This is FYI - I can change my old code.

Here is sessionInfo() where it works:

> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: x86_64-redhat-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=C              LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] ggplot2_0.8.9 proto_0.3-8   reshape_0.8.3 plyr_1.6     

loaded via a namespace (and not attached):
[1] coda_0.13-5     digest_0.4.2    lattice_0.19-17 rjags_2.2.0-2  

and where it doesn't work:

sessionInfo()
R version 2.14.2 (2012-02-29)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=C                 LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] plyr_1.7.1    ggplot2_0.9.0

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.14.2       
 [5] MASS_7.3-18        memoise_0.1        munsell_0.3        proto_0.3-9.2     
 [9] RColorBrewer_1.0-5 reshape2_1.2.1     scales_0.2.0       stringr_0.6       
[13] tools_2.14.2      
@wch
Collaborator

This looks just like a previous issue with scale_shape_identity: #402.

I don't know if the solution (changing it to a continuous scale) is the same though. linetype can take string values, so it may not play well if it's changed to continuous.

In the meantime, the "proper" solution is to use scale_linetype_identity, which tells ggplot that the linetype values should be passed directly:

ggplot(data = data.frame(x=1:3,y=1:3)) + 
            geom_point(aes(x,y)) + 
            geom_vline(aes(xintercept = c(0.5, 0.95, 1), linetype = c(2,1,2)), color = 'grey') +
            scale_linetype_identity()
@dlebauer

@wch I think you have it backward -

I don't know if the solution (changing it to a continuous scale) is the same though. linetype can take string values, so it may not play well if it's changed to continuous.

the problem is that c(1,2,1) is a continuous numeric vector; my solution was to change it to a discrete vector (e.g. as.factor). This does seem similar to issue #402, where a proposed solution was to use as.integer , although it appears that this didn't actually work.

@wch
Collaborator

@dlebauer - I was referring to changing the definition of scale_linetype from a discrete scale to a continuous scale, as 402 -- not changing the data that's passed in.

@hadley
Owner

The previous behaviour was a bug - you shouldn't be able to map linetype to a continuous value.

@hadley hadley closed this
@dlebauer

I understand your point, but wouldn't this be analogous to

with(iris, plot(Sepal.Length ~ Species, lty = c(1,2,1)))

@hadley
Owner

That would be analogous to qplot(Species, Sepal.Length, data = iris, linetype = c(1,2,1)) + scale_linetype_identity()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.