【问题标题】:ggmosaic: how to remove the thin line when the count of a factor levels is 0ggmosaic:当因子级别的计数为0时如何删除细线
【发布时间】:2017-03-05 18:14:06
【问题描述】:

我一直在尝试使用 ggmosaic 制作马赛克/Marimekko 图,但希望删除 the thin line marking a hspine with the count of 0 (second column)

这可以在 ggmosaic 中完成吗?我在小插图/帮助文件中找不到如何。下面是一个可重现的示例。

library(ggmosaic)    

happy2 <- happy
happy2$marital <- 
  ifelse(happy2$marital == "never married" & happy2$happy == "not too happy",
       NA, happy2$marital)

ggplot(happy2) + 
  geom_mosaic(aes(x = product(happy, marital), fill = happy))

【问题讨论】:

    标签: r ggplot2 mosaic-plot


    【解决方案1】:

    不知道是否可以在ggmosaic中调整,但事实证明这个情节可以很容易地用ggplot完成

    happy2 <- happy
    happy2$marital <- 
      ifelse(happy2$marital == "never married" & happy2$happy == "not too happy",
           NA, happy2$marital)
    
    ggplot(happy2) + 
      geom_histogram(aes(x = marital, fill = happy), colour = "black", 
                   width = 1, stat = "count", position = "fill") +
      scale_y_continuous(expand = c(0,0)) +
      scale_x_discrete(expand = c(0,0))
    

    【讨论】:

      猜你喜欢
      • 2012-06-23
      • 1970-01-01
      • 2015-07-24
      • 1970-01-01
      • 1970-01-01
      • 2018-12-08
      • 1970-01-01
      • 2017-02-13
      • 2021-10-17
      相关资源
      最近更新 更多