r - How does geom_tile() handle duplicate data? -
if there multiple datum @ particular x , y location, how geom_tile()
combine data?
example:
library(ggplot2) library(dplyr) mtcars %>% ggplot(aes(x=vs,y=am,fill=mpg)) + geom_tile()
which not mean:
library(ggplot2) library(dplyr) mtcars %>% group_by(vs,am) %>% summarize(mpg = mean(mpg)) %>% ggplot(aes(x=vs,y=am,fill=mpg)) + geom_tile()
you look:
library(ggplot2) library(dplyr) mtcars %>% ggplot(aes(x=vs, y=am, fill=mpg)) + geom_tile() -> gg ggplot_build(gg) -> gb gb$data[[1]] ## fill x y panel group xmin xmax ymin ymax colour size linetype alpha ## 1 #30648f 0 1 1 -1 -0.5 0.5 0.5 1.5 na 0.1 1 na ## 2 #30648f 0 1 1 -1 -0.5 0.5 0.5 1.5 na 0.1 1 na ## 3 #356e9d 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na ## 4 #316692 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 5 #29577e 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 6 #275379 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 7 #1d3f5e 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 8 #3977a9 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 9 #356e9d 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 10 #2a5982 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 11 #275277 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 12 #234a6d 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 13 #254f73 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 14 #1f4464 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 15 #132b43 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 16 #132b43 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 17 #1e4161 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 18 #51a8ea 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na ## 19 #4b9bda 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na ## 20 #56b1f7 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na ## 21 #316693 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 22 #204566 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 23 #1f4464 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 24 #1a3a57 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 25 #2a5982 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 26 #4288c1 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na ## 27 #3e81b6 0 1 1 -1 -0.5 0.5 0.5 1.5 na 0.1 1 na ## 28 #4b9bda 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na ## 29 #214769 0 1 1 -1 -0.5 0.5 0.5 1.5 na 0.1 1 na ## 30 #2c5c85 0 1 1 -1 -0.5 0.5 0.5 1.5 na 0.1 1 na ## 31 #1f4363 0 1 1 -1 -0.5 0.5 0.5 1.5 na 0.1 1 na ## 32 #316692 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na
and
mtcars %>% group_by(vs,am) %>% summarize(mpg = mean(mpg)) %>% ggplot(aes(x=vs,y=am,fill=mpg)) + geom_tile() -> gg ggplot_build(gg) -> gb gb$data[[1]] ## fill x y panel group xmin xmax ymin ymax colour size linetype alpha ## 1 #132b43 0 0 1 -1 -0.5 0.5 -0.5 0.5 na 0.1 1 na ## 2 #29577e 0 1 1 -1 -0.5 0.5 0.5 1.5 na 0.1 1 na ## 3 #2e608b 1 0 1 -1 0.5 1.5 -0.5 0.5 na 0.1 1 na ## 4 #56b1f7 1 1 1 -1 0.5 1.5 0.5 1.5 na 0.1 1 na
Comments
Post a Comment