【问题标题】:bwplot axis values are displayed incorrectlybwplot 轴值显示不正确
【发布时间】:2013-11-27 12:43:06
【问题描述】:

以下代码生成 bwplot,但 y 轴上的值是 1,2,3,4,5 而不是 10,11,12,13,14。我该如何纠正这个问题?

library(lattice)
test <- data.frame(c(rep(10,100),rep(11,100),rep(12,100),rep(13,100),rep(14,100))
               ,c(rep(rnorm(n=500,mean=2,sd=1:3))))
names(test) <- c("a","b")
bwplot(a ~ b, test)

【问题讨论】:

  • 列出你为bwplot函数使用的包。

标签: r lattice bwplot


【解决方案1】:

bwplot (lattice) 期望 ~ 左侧的因子。在绘图前显式转换

test$a = as.factor(test$a)

或(异或)使用

bwplot(as.factor(a) ~ b, test)

【讨论】:

    【解决方案2】:

    看起来您需要将 a 列转换为字符因子

    test$a=as.factor(as.character(test$a))
    bwplot(a~b, data=test)
    

    【讨论】:

      猜你喜欢
      • 2019-07-29
      • 1970-01-01
      • 2018-03-24
      • 1970-01-01
      • 2022-07-06
      • 2017-12-19
      • 1970-01-01
      • 1970-01-01
      • 2018-01-23
      相关资源
      最近更新 更多