facet_wrap() 标签中的数学符号不起作用
Math Notation in facet_wrap() Label Not Working
我的数据:
plot_df <-
structure(list(model = structure(c(1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Full",
"Point Differential"), class = "factor"), measure = structure(c(1L,
1L, 2L, 2L, 3L, 3L), .Label = c("AIC", "R^2", "Number of Predictors"
), class = "factor"), value = c(266.666394197942, 303.321585856894,
0.851698145309359, 0.713883491646847, 10, 1)), class = "data.frame", row.names = c(NA,
-6L))
我使用数据制作了以下图表:
ggplot(plot_df, aes(y=value, x=model, fill=model)) +
geom_bar(position="dodge", stat="identity") +
facet_wrap(~measure, scales='free') +
labs(title='Model Comparison', x='', y='Value', fill='Model') +
geom_text(aes(label=round(value,2)),vjust=1.25) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
第二个 facet_wrap()
窗格的标题为 R^2
,但不是数学符号。我试过使用 labeller=label_parsed()
,但它不起作用。此外,我曾尝试使用 latex2exp
包,但这也不起作用。有谁知道如何解决这个问题?
这是 labeller=label_parsed
,不是 labeller=label_parsed()
。
但除此之外,你必须将空格替换为 ~
:
levels(plot_df$measure)[3] <- "Number~of~Predictors"
ggplot(plot_df, aes(y=value, x=model, fill=model)) +
geom_bar(position="dodge", stat="identity") +
facet_wrap(~measure, scales='free', labeller = label_parsed) +
......
我的数据:
plot_df <-
structure(list(model = structure(c(1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Full",
"Point Differential"), class = "factor"), measure = structure(c(1L,
1L, 2L, 2L, 3L, 3L), .Label = c("AIC", "R^2", "Number of Predictors"
), class = "factor"), value = c(266.666394197942, 303.321585856894,
0.851698145309359, 0.713883491646847, 10, 1)), class = "data.frame", row.names = c(NA,
-6L))
我使用数据制作了以下图表:
ggplot(plot_df, aes(y=value, x=model, fill=model)) +
geom_bar(position="dodge", stat="identity") +
facet_wrap(~measure, scales='free') +
labs(title='Model Comparison', x='', y='Value', fill='Model') +
geom_text(aes(label=round(value,2)),vjust=1.25) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank())
第二个 facet_wrap()
窗格的标题为 R^2
,但不是数学符号。我试过使用 labeller=label_parsed()
,但它不起作用。此外,我曾尝试使用 latex2exp
包,但这也不起作用。有谁知道如何解决这个问题?
这是 labeller=label_parsed
,不是 labeller=label_parsed()
。
但除此之外,你必须将空格替换为 ~
:
levels(plot_df$measure)[3] <- "Number~of~Predictors"
ggplot(plot_df, aes(y=value, x=model, fill=model)) +
geom_bar(position="dodge", stat="identity") +
facet_wrap(~measure, scales='free', labeller = label_parsed) +
......