gpt4 book ai didi

r - 在 R 中,错误 "need at least one panel"是什么意思,如何解决?

转载 作者:行者123 更新时间:2023-12-04 11:15:02 31 4
gpt4 key购买 nike

以下代码来自《R in Action》一书, list 16.1:

library(lattice)
attach(mtcars)

gear <- factor(gear, levels=c(3, 4, 5),
labels=c("3 gears", "4 gears", "5 gears"))
cyl <- factor(cyl, levels=c(4, 6, 8),
labels=c("4 cylinders", "6 cylinders", "8 cylinders"))

densityplot(~mpg,
main="Density Plot",
xlab="Miles per Gallon")

densityplot(~mpg | cyl,
main="Density Plot by Number of Cylinders",
xlab="Miles per Gallon")

bwplot(cyl ~ mpg | gear,main="Box Plots by Cylinders and Gears",
xlab="Miles per Gallon", ylab="Cylinders")


xyplot(mpg ~ wt | cyl * gear,
main="Scatter Plots by Cylinders and Gears",
xlab="Car Weight", ylab="Miles per Gallon")

cloud(mpg ~ wt * qsec | cyl,
main="3D Scatter Plots by Cylinders")

dotplot(cyl ~ mpg | gear,
main="Dot Plots by Number of Gears and Cylinders",
xlab="Miles Per Gallon")

splom(mtcars[c(1, 3, 4, 5, 6)],
main="Scatter Plot Matrix for mtcars Data")

detach(mtcars)

我只能绘制第一个密度图和最后一个图 splom(...)。其余的图给我以下错误:

Error in limits.and.aspect(default.prepanel, prepanel = prepanel, have.xlim = have.xlim, : need at least one panel

这个错误是什么意思,我该如何解决?

我刚开始学习 R,我使用的版本是:

R version 3.1.0 (2014-04-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:
[1] LC_COLLATE=English_Malaysia.1252 LC_CTYPE=English_Malaysia.1252
[3] LC_MONETARY=English_Malaysia.1252 LC_NUMERIC=C
[5] LC_TIME=English_Malaysia.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] lattice_0.20-29

loaded via a namespace (and not attached):
[1] grid_3.1.0

编辑:

search() 的输出是:

 [1] ".GlobalEnv"        "mtcars"            "package:lattice"  
[4] "package:stats" "package:graphics" "package:grDevices"
[7] "package:utils" "package:datasets" "package:methods"
[10] "Autoloads" "package:base"

最佳答案

我从 QuickR 复制代码时遇到了同样的问题.我通过将 gear 和 cyl 的级别从 int 更改为 string 来解决它,因为数据集中的值都是字符串。

gear.f<-factor(gear,levels=c("3gears","4gears","5gears"),
labels=c("3gears","4gears","5gears"))
cyl.f <-factor(cyl,levels=c("4cyl","6cyl","8cyl"),
labels=c("4cyl","6cyl","8cyl"))

关于r - 在 R 中,错误 "need at least one panel"是什么意思,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24412788/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com