geom_mosaic: X轴刻度标签没有显示?

4

我正在使用ggmosaic::geom_mosaic生成马赛克图。但是我似乎无法在X轴上显示独立变量的值标签。该变量是一个带标签的因子,其级别标有"1"、"2"、"3"。我确定这一点很愚蠢,但我无法弄清楚到底发生了什么。希望能得到任何见解。

ggplot(data = mosaic)+
geom_mosaic(aes(x = product(X, Norm_Dx), fill=Norm_Dx), na.rm=TRUE)

enter image description here


请查看此Github问题:https://github.com/haleyjeppson/ggmosaic/issues/41 - Ben
1
你能提供一个可重现的数据集 mosaic 的例子吗?(参见:https://dev59.com/eG025IYBdhLWcg3whGSx) - dc37
2
@ Ben - 谢谢您指引我去 GitHub 的问题页面,我已经解决了。 - West_End_Line
2个回答

2
我建议您使用 mosaicplot
mosaicplot(table(X, Norm_Dx))

欲了解更多信息,请参考此教程


1

Github问题似乎还没有完全解决...因此,对于其他急需在ggplot中使用马赛克图的人,如果无法使github更新正常工作,则可以使用annotate:

data(Titanic)

titanic <- as.data.frame(Titanic)
titanic$Survived <- factor(titanic$Survived,
                           levels = c("Yes", "No"))

ggplot(data = titanic) +
  geom_mosaic(aes(weight = Freq, x = product(Class), fill = Survived)) +
  labs(x = "Passenger class",
       y = "Survived sinking",
       title = "Survival rate by passenger class")+      
  annotate(geom="text",x=0.43,y=-0.02,label="This                 is a                          very silly                                     solution",
           color="black",size=3)  +
  annotate(geom="text",x=-0.02,y=0.5,label="0                    0.25                  0.5                  0.75                    1",
           colour="black",size=3,angle=90)

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接