【问题标题】:Multiple indices in ggplot labelggplot标签中的多个索引
【发布时间】:2015-03-13 11:34:30
【问题描述】:

我想在条形图中添加一个包含多个索引的标签:

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")

我需要将“一些文本”替换为“a1 a2 a3”,其中数字为下标。我尝试了以下但得到错误:

annotate("text", x=1, y=0.4, parse=T, label=paste("a[1]","a[2]","a[3]",sep="     "))

【问题讨论】:

    标签: r ggplot2 plotmath


    【解决方案1】:

    以下是这样做的:

    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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-05
      • 2021-11-30
      • 1970-01-01
      • 1970-01-01
      • 2018-11-16
      • 2020-07-01
      • 1970-01-01
      相关资源
      最近更新 更多