我想在使用
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"))
谢谢,
尝试以下方法
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) + # note new argument here
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"))
使用
Treatment
设置下标格式 []
列。然后在 facet_wrap
中告诉 ggplot
按如下方式处理标签 labeller = label_parsed
。