【问题标题】:geom_mosaic: X axis tick labels not showing?geom_mosaic:X 轴刻度标签未显示?
【发布时间】:2020-07-08 16:57:50
【问题描述】:

我正在使用ggmosaic::geom_mosaic 生成马赛克图。我似乎无法让我的自变量的值标签显示在 X 轴上。变量是一个标记因子,水平标记为“1”、“2”、“3”。我确定这很愚蠢,但我无法弄清楚这里发生了什么。任何见解将不胜感激。

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

【问题讨论】:

标签: r ggplot2 mosaic-plot ggmosaic


【解决方案1】:

我建议您使用mosaicplot

mosaicplot(table(X, Norm_Dx))

更多信息请参考this tutorial

【讨论】:

    【解决方案2】:

    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)
    

    【讨论】:

      猜你喜欢
      • 2021-06-01
      • 1970-01-01
      • 2020-03-27
      • 2022-01-01
      • 2021-08-01
      • 2012-03-14
      • 1970-01-01
      • 1970-01-01
      • 2017-03-16
      相关资源
      最近更新 更多