【问题标题】:Is there a way I could reproduce the box plots using the lattice package function bwplot()有没有一种方法可以使用 lattice 包函数 bwplot() 重现箱线图
【发布时间】:2020-11-20 07:48:04
【问题描述】:
par(mai = c(1, 1, 1, 1), omi = c(0, 0, 0, 0))
set.seed(591)
(xx1 <- rnorm(20, mean = 3, sd = 3.6))
(xx2 <- rpois(40, lambda = 3.5))
(xx3 <- rchisq(31, df = 5, ncp = 0))

使用 R 基础包的箱线图代码。

box1 <- boxplot(xx1, xx2, xx3, names = c("Group-1", "Group-2", "Group-3"), cex = 0.7)

尝试使用 R 的格子包重现相同的箱线图

box2 <- bwplot(xx1, xx2, xx3, names = c("Group-1", "Group-2",  "Group-3"), cex = 0.7)

我得到错误代码

在 bwplot.numeric(xx1, xx2, xx3, cex = 0.7) 中:忽略显式数据规范

【问题讨论】:

  • 这不是错误信息,而是警告。它确实在box2 中返回了一些东西,但它与box1 不同。
  • 我觉得你想学习格子令人钦佩,但我想知道你的时间是否没有更好的用途。该软件包已被 ggplot2 取代,几乎已过时。

标签: r boxplot lattice bwplot


【解决方案1】:

您应该考虑将数据放入数据框中并使用如下所示的公式:

bwplot(values~ind, stack(list(Group1=xx1, Group2=xx2, Group3=xx3)), cex=0.7)

【讨论】:

  • 我想看看你用来创建数据框的代码...
  • @Matthew stack(list(Group1=xx1, Group2=xx2, Group3=xx3)) 是我使用的代码。它就在那里
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-30
  • 2011-12-24
  • 1970-01-01
  • 1970-01-01
  • 2020-09-02
  • 2022-11-22
  • 1970-01-01
相关资源
最近更新 更多