You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ggplot2 facet_grid实现分面图独立X轴标签的技术问询

问题:为facet_grid堆叠柱状图的不同分面设置独立X轴标签

我被这个问题困扰许久:需要绘制细菌类群的堆叠柱状图,采用二维facet_grid布局,但要为不同分面设置独立的X轴标签。我已参考以下Stack Overflow帖子,但仍未解决问题:

  • Force x-axis labels on facet_grid ggplot: drop lables
  • Force x-axis labels on facet_grid ggplot: x-axis labels differ per row
  • Force X axis text on for all facets of a facet_grid plot

我的数据结构如下:

structure(list(variable = structure(c(1L, 1L, 1L, 15L, 15L, 15L, 8L, 8L, 8L, 14L, 14L, 14L, 11L, 11L, 11L, 6L, 6L, 6L, 9L, 9L, 9L, 2L, 2L, 2L, 4L, 4L, 4L, 13L, 13L, 13L, 12L, 12L, 12L, 10L, 10L, 10L, 3L, 3L, 3L, 7L, 7L, 7L, 5L, 5L, 5L), .Label = c("Control-5C10-7F", "Control-5C20-7M", "Treatment-5T16-7M", "Treatment-5T10-7F", "Treatment-5T20-7F", "Control-5C18-7F", "Treatment-5T17-7F", "Control-5C11-7F", "Control-5C19-7M", "Treatment-5T16-7F", "Control-5C17-7F", "Treatment-5T11-7M", "Treatment-5T10-7M", "Control-5C11-7M", "Control-5C10-7M"), class = "factor"), value = c(0.331838128419, 0.352404886374, 0.0718854601356, 0.354207630618, 0.294475795902, 0.0531792027053, 0.29236332445, 0.468273675353, 0.0607016856192, 0.293872306838, 0.362196681338, 0.066892937885, 0.365593390631, 0.307405564259, 0.0440421535284, 0.355757725414, 0.344565656834, 0.0385728714381, 0.321804993859, 0.357477936005, 0.0189435852408, 0.29485205349, 0.323279812948, 0.0613479971185, 0.330899082108, 0.0950818222943, 0.00477515444166, 0.382399029908, 0.118943005246, 0.00476898392234, 0.369726433283, 0.163932867784, 0.00531688661114, 0.309218704951, 0.146836936202, 0.196198995646, 0.395112160831, 0.185072972204, 0.00267743643869, 0.306483893184, 0.330640754636, 0.0715509081212, 0.301275805191, 0.388917814857, 0.0356065705157 ), Type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Control", "Treatment"), class = "factor"), Time.Sex = structure(c(2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("7d.M", "7d.F"), class = "factor"), IndividualID = c("5C10", "5C10", "5C10", "5C10", "5C10", "5C10", "5C11", "5C11", "5C11", "5C11", "5C11", "5C11", "5C17", "5C17", "5C17", "5C18", "5C18", "5C18", "5C19", "5C19", "5C19", "5C20", "5C20", "5C20", "5T10", "5T10", "5T10", "5T10", "5T10", "5T10", "5T11", "5T11", "5T11", "5T16", "5T16", "5T16", "5T16", "5T16", "5T16", "5T17", "5T17", "5T17", "5T20", "5T20", "5T20" ), Sex = c("F", "F", "F", "M", "M", "M", "F", "F", "F", "M", "M", "M", "F", "F", "F", "F", "F", "F", "M", "M", "M", "M", "M", "M", "F", "F", "F", "M", "M", "M", "M", "M", "M", "F", "F", "F", "M", "M", "M", "F", "F", "F", "F", "F", "F"), Rep = c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 4, 3, 3, 3, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4), IndividualID.Sex = c("5C10.F", "5C10.F", "5C10.F", "5C10.M", "5C10.M", "5C10.M", "5C11.F", "5C11.F", "5C11.F", "5C11.M", "5C11.M", "5C11.M", "5C17.F", "5C17.F", "5C17.F", "5C18.F", "5C18.F", "5C18.F", "5C19.M", "5C19.M", "5C19.M", "5C20.M", "5C20.M", "5C20.M", "5T10.F", "5T10.F", "5T10.F", "5T10.M", "5T10.M", "5T10.M", "5T11.M", "5T11.M", "5T11.M", "5T16.F", "5T16.F", "5T16.F", "5T16.M", "5T16.M", "5T16.M", "5T17.F", "5T17.F", "5T17.F", "5T20.F", "5T20.F", "5T20.F"), Genus = c("o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae NK4A136 group", "o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae NK4A136 group", "o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae NK4A136 group", "o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae NK4A136 group", "o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae NK4A136 group", "o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae NK4A136 group", "o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae NK4A136 group", "o__Bacteroidales;g__Parabacteroides", "o__Lactobacillales;g__Lactobacillus", "o__Clostridiales;g__Lachnospiraceae N"))

内容的提问来源于stack exchange,提问作者julio514

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:19:11