在同一图上绘制9个图表的最佳方法?
试图对玻璃数据集中所有预测值进行直方图。我最初使用par(mfrow = c(3,3))
在同一窗口上绘制所有9个预测指标,但遇到了边距太大的错误。没关系。无论如何,写历史记录(玻璃$ x)九次效率低下。
因此,我尝试一次绘制它们。我将数据子集征用,以便仅保留数字列,但是出现了一个错误,说它们不是数字。我已经验证了所有列都是数字。我在做什么错?
library(mlbench)
data(Glass)
library(lattice)
par(mfrow=c(3,3))
hist(Glass$RI)
> Error in plot.new() : figure margins too large
Glass2=subset(Glass[1:9])
hist(Glass2)
> Error in hist.default(Glass2) : 'x' must be numeric
Trying to make a histogram of all the predictor values in the Glass dataset. I initially used par(mfrow=c(3,3))
to plot all 9 predictors on the same window, but got an error that the margins were too large. That's okay. Writing hist(Glass$X) nine times would've been inefficient anyway.
So then I tried to plot them all at once. I subset the data so that only the numeric columns remained, but got an error saying that they weren't numeric. I've already verified all columns are numeric. What am I doing wrong?
library(mlbench)
data(Glass)
library(lattice)
par(mfrow=c(3,3))
hist(Glass$RI)
> Error in plot.new() : figure margins too large
Glass2=subset(Glass[1:9])
hist(Glass2)
> Error in hist.default(Glass2) : 'x' must be numeric
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个整洁的替代方案。
结果:
Here's a tidyverse alternative.
Result:
将数据归为新的数据框架。确保您的情节窗口确实很大,否则您会发现保证金太小的错误。
Subset the data into a new data frame, X. Instead of typing out X$x nine times, use a for loop. Make sure your plot window is really big or you'll get an error that the margins are too small.