ggplot 标签中的多个索引
Multiple indices in ggplot label
我想向条形图添加包含多个索引的标签:
data<-as.data.frame(c("A"))
colnames(data)<-"A"
data$B<-5
ggplot(data, aes(x=A, y=B)) +
geom_bar(stat="identity", colour="black", position="dodge", size=0.25, width=0.8, alpha=0.8) +
annotate("text", x=1, y=2.5, label="some text")
我需要将 "some text" 替换为 "a1 a2 a3",其中数字为下标。我尝试了以下但出现错误:
annotate("text", x=1, y=0.4, parse=T, label=paste("a[1]","a[2]","a[3]",sep=" "))
执行以下操作:
ggplot(data, aes(x=A, y=B)) + geom_bar(stat="identity", colour="black", position="dodge", size=0.25, width=0.8, alpha=0.8) + annotate("text", x=1, y=2.5, label="~a[1]~a[2]~a[3]", parse=TRUE)
我想向条形图添加包含多个索引的标签:
data<-as.data.frame(c("A"))
colnames(data)<-"A"
data$B<-5
ggplot(data, aes(x=A, y=B)) +
geom_bar(stat="identity", colour="black", position="dodge", size=0.25, width=0.8, alpha=0.8) +
annotate("text", x=1, y=2.5, label="some text")
我需要将 "some text" 替换为 "a1 a2 a3",其中数字为下标。我尝试了以下但出现错误:
annotate("text", x=1, y=0.4, parse=T, label=paste("a[1]","a[2]","a[3]",sep=" "))
执行以下操作:
ggplot(data, aes(x=A, y=B)) + geom_bar(stat="identity", colour="black", position="dodge", size=0.25, width=0.8, alpha=0.8) + annotate("text", x=1, y=2.5, label="~a[1]~a[2]~a[3]", parse=TRUE)