Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R:在ggplot2中重新标记面包装标题_R_Ggplot2_Boxplot_Facet Wrap - Fatal编程技术网

R:在ggplot2中重新标记面包装标题

R:在ggplot2中重新标记面包装标题,r,ggplot2,boxplot,facet-wrap,R,Ggplot2,Boxplot,Facet Wrap,试试这种方法。您可以使用所需的组合直接为标签创建变量,然后使用label\u parsed对其进行计算。代码如下: dummy_data %>% ggplot(aes(x = method, y = mse, fill = method)) + geom_boxplot() + facet_wrap(~csh, labeller = labeller(csh = c("0" = expression(paste(beta[0])),

试试这种方法。您可以使用所需的组合直接为标签创建变量,然后使用
label\u parsed
对其进行计算。代码如下:

dummy_data %>%
  ggplot(aes(x = method, y = mse, fill = method)) +
  geom_boxplot() +
  facet_wrap(~csh, labeller = labeller(csh = c("0" = expression(paste(beta[0])),
                                               "1" = expression(paste(beta[1])),
                                               "2" = expression(paste(beta[2]))))) +
  theme_bw() +
  theme(axis.text.x=element_blank())
输出:

更新:

library(ggplot2)
library(dplyr)
#Code
dummy_data %>%
  mutate(csh=paste('beta[',csh,']')) %>%
  ggplot(aes(x = method, y = mse, fill = method)) +
  geom_boxplot() +
  facet_wrap(~csh, labeller = label_parsed) +
  theme_bw() +
  theme(axis.text.x=element_blank())
输出:


谢谢。一个后续问题。如果我希望标签改为beta=0、beta=1和beta=2呢?我尝试了
mutate(csh=paste('beta=',csh))
但这并没有给我想要的。@YQC让我在这一刻为你添加一个更新@YQC我已经为您添加了一个更新。我希望这对你有帮助!!!您只需要
dummy_data%>%ggplot(aes(x=method,y=mse,fill=method))+geom_boxplot()+facet_wrap(~csh,labeller=label_bquote(beta[(csh)])
library(ggplot2)
library(dplyr)
#Code
dummy_data %>%
  mutate(csh=paste('beta[',csh,']')) %>%
  ggplot(aes(x = method, y = mse, fill = method)) +
  geom_boxplot() +
  facet_wrap(~csh, labeller = label_parsed) +
  theme_bw() +
  theme(axis.text.x=element_blank())
#Code 2
dummy_data %>%
  mutate(csh=paste("beta==", csh)) %>%
  ggplot(aes(x = method, y = mse, fill = method)) +
  geom_boxplot() +
  facet_wrap(~csh,labeller = label_parsed) +
  theme_bw() +
  theme(axis.text.x=element_blank())