【问题标题】:Keep the default axis values but just turn them to percentages保留默认轴值,但只需将它们转换为百分比
【发布时间】:2017-08-14 18:40:39
【问题描述】:

我想知道如何在我的图中将默认的 y 轴值保留为 R 而只是将它们转换为百分比?具体来说,如果我们需要使用axis(),我们应该如何在axis()中指定“at =”来保持默认的打勾值?

这里有一个例子:

x = rbinom(10, 100, .7)
plot(x)

以下是我认为可能有效但无效的方法:

plot(x, yaxt = "n")
tk = par("yaxp")
axis(2, at = seq(tk[1], tk[2], l = tk[3]), labels = paste0(seq(tk[1], tk[2], l = tk[3]), "%"))

【问题讨论】:

    标签: r plot axis-labels


    【解决方案1】:

    这将为您完成工作:

    plot(x, yaxt="n")
       axis(2, at=axTicks(2), labels=paste0("%", axTicks(2)))
    

    下面,你可以看到plot(x)的结果和上面的解决方案并排:

       set.seed(123)
       x = rbinom(10, 100, .7)
    
       plot(x)
    
       plot(x, yaxt="n")
       axis(2, at=axTicks(2), labels=paste0("%", axTicks(2)))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-07
      • 2012-02-17
      • 2019-07-03
      • 2016-03-26
      • 1970-01-01
      相关资源
      最近更新 更多