geom_tile() potential issues with width, height #651

Closed
tengfei opened this Issue Aug 21, 2012 · 2 comments

Projects

None yet

2 participants

tengfei commented Aug 21, 2012

Maybe I am wrong, I always think if the aesthetics control is not mapped to variable, I don't have to pass it with aes(). But looks it's not true with geom_tile.

  1. Here is an example
# Generate data
library(ggplot2)
pp <- function (n,r=4){ 
  x <- seq(-r*pi, r*pi, len=n) 
  df <- expand.grid(x=x, y=x) 
  df$r <- sqrt(df$x^2 + df$y^2) 
  df$z <- cos(df$r^2)*exp(-df$r/6) 
  df 
} 

## doens't work
ggplot(pp(20)) + geom_tile(aes(x = x, y = y, fill = z), width = 0.3, height = 0.3)
## works
ggplot(pp(20)) + geom_tile(aes(x = x, y = y, fill = z, width = 0.3, height = 0.3))
> sessionInfo()
R Under development (unstable) (2012-07-17 r59871)
Platform: x86_64-unknown-linux-gnu (64-bit)

locale:
 [1] LC_CTYPE=zh_CN.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] ggplot2_0.9.1

loaded via a namespace (and not attached):
 [1] colorspace_1.1-1   compiler_2.16.0    dichromat_1.2-4    digest_0.5.1      
 [5] grid_2.16.0        labeling_0.1       MASS_7.3-19        memoise_0.1       
 [9] munsell_0.3        plyr_1.7.1         proto_0.3-9.2      RColorBrewer_1.0-5
[13] reshape2_1.2.1     scales_0.2.1       stringr_0.6.1      tools_2.16.0    
Collaborator
wch commented Sep 14, 2012

This looks like an issue with stat_identity:

# Width works with bin
ggplot(PlantGrowth, aes(x=group)) + geom_boxplot(width=.2, stat="bin")

# Width doesn't work with identity
pgsub <- PlantGrowth[c(1,11,21), ]
ggplot(pgsub, aes(x=group, y=weight)) + geom_bar(width=.2, stat="identity")

# Width works when in aes()
ggplot(pgsub, aes(x=group, y=weight)) + geom_bar(aes(width=.2), stat="identity")
Collaborator
wch commented Oct 15, 2012

Fixed in 06914a7.

@wch wch closed this Oct 15, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment