此R脚本未提供输出。 请帮帮我。 R代码是:
names = colnames(train)
for(i in 2:80)
{
ggplot(train, aes_string(x = names[i])) + geom_histogram(aes(y=..density..),
bins = 50,colour="black", fill="white") + geom_density(alpha=.2, fill= "#FF8C00")
}
列车数据框包含1460行和81列,每列都是数字类型。 第一列是Id,所以我从2到80开始循环。 控制台没有显示任何错误,也没有显示绘图。
答案 0 :(得分:1)
在for循环中,您必须显式调用print
函数。以下是对此明确调用它的需要的可重现性演示。
library(ggplot2)
# This will not give any output
for(i in 1:1){
ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point()
}
# This will give output
for(i in 1:1){
print(ggplot(iris, aes(Sepal.Length, Sepal.Width)) + geom_point())
}