【问题标题】:how to use expression in in names.arg function如何在 names.arg 函数中使用表达式
【发布时间】:2014-03-08 01:44:22
【问题描述】:

我的条形图中有几种碳化合物,但我需要为每个碳化合物下标,例如C*12*-C*16*, C*17*-C*25*,C*26*-C*32*,C*33*-C*37*.

我正在尝试使用表达式函数,但它与 barplot 上的 names.arg 函数不兼容。请看目前为止的代码:

barplot(t(as.matrix(alkane)),
  ylim=c(0,100),
  names.arg=c("C12-C16","C17-C25","C26-C32","C33-C37"),
  xlab="Hydrocarbons analysed after 21 days",
  ylab="% loss in concentration relative to day 0",
  cex.lab=0.8,
  cex.axis=0.8,
  cex.names=0.8,
  cex.main=0.8,
  beside=TRUE,
  col=c("blue","red"))

任何帮助将不胜感激。

【问题讨论】:

    标签: r expression plotmath


    【解决方案1】:

    正如您通过突出显示看到的那样,您的names.arg 的格式不正确,请检查要配对的"

    names.arg=c("C12-C16","C17-C25","C26-C32","C33-C37"),
    

    【讨论】:

    • 在这个网站上输入错误。我仍然想不出一种方法来使用表达式在每个 C 的数字上引入下标。
    【解决方案2】:

    我想你正在寻找这个:

    set.seed(1)
    x <- matrix(rbeta(8, 5, 5), 2, 4)
    
    barplot(x, names.arg = 
              expression(C[12]-C[16], C[17]-C[25], C[26]-C[32],C[33]-C[37]))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-05
      • 1970-01-01
      • 2016-07-02
      • 1970-01-01
      • 2023-01-09
      • 1970-01-01
      相关资源
      最近更新 更多