Re: Missing colors in gradient legend

555 views
Skip to first unread message

Eduardo Ibanez

unread,
Oct 16, 2012, 9:13:27 AM10/16/12
to ggp...@googlegroups.com
Unfortunately, loading the scales package didn't solve the issue. I have copied my sessionInfo below for more information.

The scale fails to show up in the graphics window in R and also if I save it to png, bmp, tiff, or JPEG. However, if it works fine if I save the graph to PDF.

Is it possible to run just the code that creates the legend? I might be able to diagnose my problem more easily that way.

Thanks,
Eduardo




> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

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

other attached packages:
[1] scales_0.2.2    ggplot2_0.9.2.1

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2      
 [4] grid_2.15.1        gtable_0.1.1       labeling_0.1      
 [7] MASS_7.3-22        memoise_0.1        munsell_0.4       
[10] plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5
[13] reshape2_1.2.1     stringr_0.6.1      tools_2.15.1 




On Tuesday, October 16, 2012 5:31:58 AM UTC-6, hywelm wrote:
Try library(scales)

On Monday, 15 October 2012 19:17:59 UTC+1, Eduardo Ibanez wrote:
Hi,

I am having problems with the gradient scale when applied to color or fill. I am running R version 2.15.1 and ggplot v 0.9.2.1 under Windows 2008 Server x64 (SP1).

As you can see in the image below, the legend does not show the appropriate colors used in the main part of the graph. I have run the code below in 4 computers with the same setup and two of them showed the correct legend and the other two were incorrect.

Does the gradient scale use an additional package that could be causing this behaviour?

Thanks,
Eduardo
 

library(ggplot2)
dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
qplot(x, y, data=dsub, colour=z)) +
  scale_colour_gradient(limits=c(3, 4))



Brandon Hurr

unread,
Oct 16, 2012, 9:20:29 AM10/16/12
to Eduardo Ibanez, ggp...@googlegroups.com
I can't replicate this on my machine (MacMini). I know that's not really helpful, but it's FYI in case someone else has an idea why. 

> sessionInfo()
R version 2.15.1 (2012-06-22)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] ggplot2_0.9.2.1

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   dichromat_1.2-4    digest_0.5.2       grid_2.15.1        gtable_0.1.1       labeling_0.1      
 [7] MASS_7.3-21        memoise_0.1        munsell_0.4        plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5
[13] reshape2_1.2.1     scales_0.2.2       stringr_0.6.1     


--
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

Eduardo Ibanez

unread,
Oct 16, 2012, 10:35:53 AM10/16/12
to ggp...@googlegroups.com

Thanks, Brandon. I changed the background color of the legend and it looks like the tick marks are there. The color bar is not appearing.


library(ggplot2)
library(scales)dsub <- subset(diamonds, x > 5 & x < 6 & y > 5 & y < 6)
  qplot(x, y, data=dsub, colour=z) +
  scale_colour_gradient(limits=c(3, 4)) +
  theme(legend.background = element_rect(fill = 'purple'))

Eduardo Ibanez

unread,
Oct 16, 2012, 12:42:00 PM10/16/12
to ggp...@googlegroups.com
The following examples (http://stackoverflow.com/questions/11070101/2d-color-gradient-plot-in-r) involve gradients and also fail (PDFs are still produced correctly). Thus, this is not an issue with ggplot2 but something else. For now, I am going to revert to the legend that was used before 0.9.

Thanks all for your feedback. If you have any others ideas, please keep them coming because I would like to be able to use the gradient.



# Gradient example 1
m = tcrossprod(sin(seq(0,pi,length=1e2)), cos(seq(0, 3*pi, length=1e2)))
cols = matrix(hcl(h=scales::rescale(m, c(0, 360))), nrow(m))
grid::grid.raster(cols)

# Gradient example 2
library(grid)
library(scales)
m = tcrossprod(seq(1,2,length=1e2), seq(2, 3, length=1e2))
pal <- gradient_n_pal(c("red","green","yellow","blue"), values = c(2, 3, 4, 6), space = "Lab")
cols = matrix(pal(m), nrow(m))
grid.raster(cols)
Reply all
Reply to author
Forward
0 new messages