ggplot中的不同方面标题
Varying facet title in ggplot
我有以下数据框:
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))
但它似乎忽略了贴标机。
有什么想法吗?
您可以只使用年龄作为分面。
ggplot(df, aes(x=Time, y=TestResult)) +
geom_line() +
geom_point() +
facet_wrap(~Age)
我有以下数据框:
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))
但它似乎忽略了贴标机。
有什么想法吗?
您可以只使用年龄作为分面。
ggplot(df, aes(x=Time, y=TestResult)) +
geom_line() +
geom_point() +
facet_wrap(~Age)