我有以下数据集:
Category <- c("Bankpass", "Bankpass", "Bankpass", "Moving", "Moving")
Subcategory <- c("Stolen", "Lost", "Login", "Address", "New contract")
Weight <- c(10,20,13,40,20)
Duration <- as.character(c(0.2,0.4,0.5,0.44,0.66))
df <- data.frame(Category, Subcategory, Weight, Duration)我使用它创建以下情节:
#install.packages("ggmosaic")
ggplot(data = df) +
geom_mosaic(aes(weight = Weight, x = product(Category), fill=Duration),
na.rm=TRUE) + theme(axis.text.x=element_text(angle=-25, hjust= .1))不过,我在酒吧里看到的小片是没有道理的。

我有什么办法摆脱他们吗?
发布于 2017-12-29 18:25:38
在geom_mosaic中添加offset = 0。
ggplot(data = df) +
geom_mosaic(aes(weight = Weight, x = product(Category), fill=Duration),
offset = 0, na.rm=TRUE) +
theme(axis.text.x=element_text(angle=-25, hjust= .1))

发布于 2017-12-29 20:22:10
我在酒吧里看到一些小片没有道理。
看来,geom_mosaic调用正在绘制这两个类别的所有级别的子类别。许多人会认为这是一个“特性”,而不是“bug”。请参阅下面的图,它使用您的确切调用,但使用fill = Subcategory

您还可以通过使用table(df$Category, df$Subcategory)命令看到这一点,该命令显示
Address Login Lost New contract Stolen Bankpass 0 1 1 0 1 Moving 1 0 0 1 0
无论如何,最简单的解决方案就是上面提到的@esm,使用offset = 0隐藏这些没有条目的因素。
https://stackoverflow.com/questions/48024429
复制相似问题