答案 0 :(得分:4)
你可以这样做:
示例数据:
df=structure(list(variable = c(13L, 13L, 13L, 13L, 14L, 14L, 14L,
14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L,
18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L), value = c(480L, 720L,
460L, 220L, 780L, 350L, 480L, 240L, 431L, 377L, 179L, 876L, 295L,
255L, 560L, 789L, 670L, 340L, 60L, 820L, 360L, 615L, 735L, 100L,
190L, 345L, 1260L, 75L), grp = c("A", "A", "A", "A", "A", "A",
"A", "A", "A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B",
"B", "B", "B", "B", "B", "B", "B", "B", "B")), .Names = c("variable",
"value", "grp"), row.names = c(NA, -28L), class = "data.frame")
library(ggplot2)
ggplot(df,aes(value)) +
geom_density() +
facet_grid(grp ~variable,labeller =labeller(.cols = function(string) paste(string, "°C")))
或
ggplot(df,aes(value)) +
geom_density() +
facet_grid(grp ~variable,labeller =labeller(variable = function(string) paste(string, "°C")))