In ggmosaic
, I want every cell stand for the value sumx
, but the geom_mosaic can’t support it (Default, in geom_mosaic ,the cell stand the numbers of the data rows, like geom_histogram ).
Below code, i repeat the rows data according the value sumx
, it’s working well .
Is the any way to simplify this or have replacement code/geom_xx ?
When the value is huge, current way maybe inefficiency. Thank!
library(tidyverse)
library(ggmosaic)
df <- diamonds %>% group_by(cut,color) %>% summarise(sumx = sum(x))
df2 <- df[rep(c(1:nrow(df)),df$sumx),]
ggplot(data = df2) +
geom_mosaic(aes(x = product(cut),fill=color))