【问题标题】:Remove space at bottom of facet删除刻面底部的空间
【发布时间】:2019-07-01 11:21:36
【问题描述】:

我正在使用#ggplot 和 facet 绘制图表,但没有得到我想要的结果。 使用下面显示的代码,我总是在标签和条之间留出一些空间

即使添加 switch="y" 我也可以在左侧移动构面标题,但即使使用 axis.ticks = element_blank(),空间仍然存在。

这是我坚持的结果 https://imgur.com/a/neTTpil

编辑 感谢@StéphaneLaurent,我添加了 scale_y_continuous(expand = c(0,0)) 解决gap问题的参数,我现在要做的是用facet替换label,反之亦然

df=data.frame(
    CHANNEL=c("IN","IN","IN","OUT","OUT","OUT"),
    AGEING=c("A","B","C","A","B","C"),  
DELTA=c(4.84904880066170385,4.44191343963553464,3.32480818414322288,1.74081237911025144,1.86749666518452639,1.74672489082969418)
)
ggplot(df, aes(AGEING, DELTA, fill=CHANNEL)) +
    geom_bar(stat="identity") + coord_flip() +
    facet_grid(vars(CHANNEL), space = "free", switch="y") +
    theme(legend.position = "none",
        axis.ticks = element_blank(),
        axis.title.x = element_blank(),
        axis.title.y = element_blank()
        )

【问题讨论】:

  • 感谢@StéphaneLaurent,展开解决了部分删除标签之间空格的问题,但我仍然不知道如何交换构面和标签
  • 请为您的问题添加更多详细信息。 “我没有达到我想要的结果”并不能很清楚你想要什么。 “我仍然不知道如何交换构面和标签”暗示这是您问题的一部分,但我没有看到。

标签: r ggplot2 facet-grid


【解决方案1】:

在第一个问题的 cmets 中提到的 expand 选项之上,您可以将 facet labelstheme(strip.placement = "outside") 放在外面:

ggplot(df, aes(AGEING, DELTA, fill=CHANNEL)) +
  geom_bar(stat="identity") + coord_flip() +
  facet_grid(vars(CHANNEL), space = "free", switch="y") +
  scale_y_continuous(expand = c(0,0)) +
  theme(legend.position = "none",
        axis.ticks = element_blank(),
        axis.title.x = element_blank(),
        axis.title.y = element_blank()
  ) +
  theme(strip.placement = "outside")

导致:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多