楼主: skyonefly
8506 2

[问答] R语言 ggplot2 doesn't know how to deal with data of class matrix [推广有奖]

  • 0关注
  • 0粉丝

初中生

23%

还不是VIP/贵宾

-

威望
0
论坛币
0 个
通用积分
0
学术水平
0 点
热心指数
0 点
信用等级
0 点
经验
68 点
帖子
8
精华
0
在线时间
15 小时
注册时间
2015-10-24
最后登录
2016-3-31

楼主
skyonefly 发表于 2015-11-25 10:38:38 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
> write.csv(submission, file = "D:/Kaggle/1_random_forest_r_submission.csv", row.names=FALSE)
>
> imp <- importance(rf, type=1)
> featureImportance <- data.frame(Feature=row.names(imp), Importance=imp[,1])
> p <- ggplot(imp, aes(x=reorder(Feature,Importance), y=Importance) )
错误: ggplot2 doesn't know how to deal with data of class matrix
>             +
+   geom_bar() +   
+   coord_flip() +
+   theme_light(base_size=20) +
+   xlab("") +
+   ylab("Importance")
错误于+geom_bar() : 一进列运算符的参数不对
>   ggtitle("Random Forest Feature Importance\n") +
+   theme(plot.title=element_text(size=18))
错误: 没有"ggtitle"这个函数
>
> ggsave("2_feature_importance.png", p)

运行的   Kagg'le里的一个R语言的例子  我明明featureImportance是data.frame 类型 数据 为什么会出现错误: ggplot2 doesn't know how to deal with data of class matrix

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:ggplot2 matrix gplot doesn Data R语言 Kaggle ggplot绘图

沙发
jgchen1966 发表于 2015-11-25 12:02:17
在ggplot2 中,所有函数中data 变量,均要data.frame 类型!!!
因此,将matrix 用as.data.frame 转为data.frame
因为 Hadley Wickham 推崇data.frame 所至,他开发的packages 大都如此!!

藤椅
skyonefly 发表于 2015-11-25 15:37:57
jgchen1966 发表于 2015-11-25 12:02
在ggplot2 中,所有函数中data 变量,均要data.frame 类型!!!
因此,将matrix 用as.data.frame 转为dat ...
粗心了  变量写错了

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2026-2-2 06:36