【问题标题】:Varying facet title in ggplot [duplicate]ggplot中的不同构面标题[重复]
【发布时间】:2019-12-02 21:50:37
【问题描述】:

我有以下数据框:

df = structure(list(Age = c(85.3008017936344, 85.3008017936344, 
85.3008017936344, 
85.3008017936344, 57.8700505396495, 57.8700505396495, 57.8700505396495, 
57.8700505396495, 57.8700505396495, 72.7514762882082, 72.7514762882082, 
72.7514762882082, 72.7514762882082), ID = c("37", "37", "37", 
"37", "38", "38", "38", "38", "38", "39", "39", "39", "39"), 
TestResult = c(13.57123199512, 31.915548177134, 37.956556605893, 
31.9504259460811, 6.11843008606919, 41.3992419385478, 31.0176354057889, 
37.3284699517338, 40.3868204693566, 13.2087095959212, 37.3690920066042, 
34.3923572397983, 45.2206934197729), Time = c(0, -0.25, -1.25, 
-2.75, 0, -0.25, -0.75, -1.25, -1.75, 0, -0.25, -0.75, -1.25
)), row.names = c(NA, -13L), class = c("tbl_df", "tbl", "data.frame"
))

我想为每位患者绘制测试结果与时间的关系图,并且我希望分面标题包含患者的年龄。

我尝试了以下方法:

ggplot(df, aes(Time, TestResult)) +
  geom_point() +
  geom_line() + 
  facet_wrap(~ID, labeller = as_labeller(df$Age))

但它似乎忽略了贴标机。

有什么想法吗?

【问题讨论】:

    标签: r ggplot2 facet-wrap


    【解决方案1】:

    您可以只使用年龄作为方面。

    ggplot(df, aes(x=Time, y=TestResult)) +
       geom_line() +
       geom_point() +
       facet_wrap(~Age)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      • 2019-06-12
      • 2012-12-25
      • 2022-10-01
      • 2020-07-14
      相关资源
      最近更新 更多