R 如何使用ggplot 2为箱线图上的标签添加下标

R 如何使用ggplot 2为箱线图上的标签添加下标,r,ggplot2,boxplot,R,Ggplot2,Boxplot,在x轴上添加类别的下标时遇到问题。我的密码是: xlab("Treatment Combination") + ylab("CS Activity (IU/gfw)") + scale_x_discrete(labels = c("Control/Control" = "MControl à LControl", "Hypoxic/Hypoxic" = "MHypoxia à LHypoxia"))+ 我试图将“MControláLCon

在x轴上添加类别的下标时遇到问题。我的密码是:

xlab("Treatment Combination") +
ylab("CS Activity (IU/gfw)") +
scale_x_discrete(labels = c("Control/Control" = "MControl à LControl",
                            "Hypoxic/Hypoxic" = "MHypoxia à LHypoxia"))+
我试图将
“MControláLControl”
更改为
“M”
,作为常规
“Control”
之前的下标,并再次将
“L”
更改为常规
“Control”
之前的下标

此图显示了不带下标“M”和“L”的类别标签:

有没有关于如何订阅这些内容的想法


提前感谢您的帮助

您可以使用
expression
函数执行类似操作。请注意,如果编写
表达式([M]*“ControláLControl”)
,则不会解析
表达式。您总是需要在下标括号之前添加一些内容。在您的例子中,代码块应该是
表达式(“[M]*”Controlá“[L]*”Control”)
。见下例:

library(ggplot2)

# Base example
iris %>% 
  as_tibble() %>% 
  ggplot(aes(x = Species, y = Sepal.Length)) +
  geom_boxplot() +
  # Here comes the magic!
  scale_x_discrete(name = "",
                   # Note that we put an empty space before the subscript
                   labels = c(expression(""[M]*"Setosa"),
                              expression(""[L]*"Versicolor"),
                              expression(""[Q]*"Virginica")))

您可以使用
expression
函数执行类似操作。请注意,如果编写
表达式([M]*“ControláLControl”)
,则不会解析
表达式。您总是需要在下标括号之前添加一些内容。在您的例子中,代码块应该是
表达式(“[M]*”Controlá“[L]*”Control”)
。见下例:

library(ggplot2)

# Base example
iris %>% 
  as_tibble() %>% 
  ggplot(aes(x = Species, y = Sepal.Length)) +
  geom_boxplot() +
  # Here comes the magic!
  scale_x_discrete(name = "",
                   # Note that we put an empty space before the subscript
                   labels = c(expression(""[M]*"Setosa"),
                              expression(""[L]*"Versicolor"),
                              expression(""[Q]*"Virginica")))

你试过这个问题的答案了吗?你试过这个问题的答案了吗?也在。成功!!谢谢你的帮助!成功!!谢谢你的帮助!