在R中,使用facet_wrap()时如何将面板标题转换为下标?

问题描述 投票:0回答:1

我想在使用

facet_wrap()
时将图表的面板标题更改为下标。例如,当我创建图表时,我想更改标题“B/R1.1”或“B.R2.1”以显示为右图,仅显示数字作为下标。你能告诉我该怎么做吗?

df = data.frame(
  Genotype = c("A", "B", "A", "B"),
  Treatment = c("B/R1.1", "B/R1.1", "B/R2.1", "B/R2.1"),
  yield = c(100, 150, 88, 120)
)

ggplot(df, aes(x=Genotype, y=yield)) +
  geom_bar(stat="identity", position="dodge", width=0.9, size=1) +
  facet_wrap(~ Treatment, scales="free") +
  theme_classic(base_size=22, base_family="serif")+
  theme(axis.line=element_line(linewidth=0.5, colour="black"),
        strip.background=element_rect(color="white",
                                      linewidth=0.5,linetype="solid"))

enter image description here

谢谢,

r facet-wrap subscript
1个回答
0
投票

尝试

df = data.frame(
  Genotype = c("A", "B", "A", "B"),
  Treatment = c("B/R[1.1]", "B/R[1.1]", "B/R[2.1]", "B/R[2.1]"),
  yield = c(100, 150, 88, 120)
)

ggplot(df, aes(x=Genotype, y=yield)) +
  geom_bar(stat="identity", position="dodge", width=0.9, size=1) +
  facet_wrap(~ Treatment, scales="free", labeller = label_parsed) +
  theme_classic(base_size=22, base_family="serif")+
  theme(axis.line=element_line(linewidth=0.5, colour="black"),
        strip.background=element_rect(color="white",
                                      linewidth=0.5,linetype="solid"))
© www.soinside.com 2019 - 2024. All rights reserved.