提供给ggplot2 geom_point图中的scale_x_连续的非连续变量
我有一个有两列的表,它们都是连续数据。我检查了 csv 文件以确保这些列中只有数字值。然而,当我绘制它们时,其中一个似乎被视为非连续数据,并且我得到:错误:提供给scale_x_continuous的非连续变量。
这是我的表格的一个小版本,
budget gross
1 234 4234
2 42342 2323
3 22165 346
4 290 452
...
我试图创建一个散点图,其中 y 轴为总数,x 轴为预算。 我尝试了这个,但出现了上述错误。
p <- ggplot(test, aes(Budget, Gross))+geom_point(alpha=I(1/5), aes(colour=Budget))+ opts(titles="Movies per Year", panel.grid.major = theme_blank(), panel.grid.minor = theme_blank())+scale_x_continuous()
太感谢了
I have a table that has two columns both of them are continuous data. I checked the csv file to make sure there are only numeric values in those columns. However, when I plot them one of them seems to be taken as non-continuous data, and I get: Error: Non-continuous variable supplied to scale_x_continuous.
This is a small version of my table
budget gross
1 234 4234
2 42342 2323
3 22165 346
4 290 452
...
I am trying to create a scatter plot where the gross numbers are in the y axis and the budget in the x axis.
I tried this but I get the fore-mentioned error.
p <- ggplot(test, aes(Budget, Gross))+geom_point(alpha=I(1/5), aes(colour=Budget))+ opts(titles="Movies per Year", panel.grid.major = theme_blank(), panel.grid.minor = theme_blank())+scale_x_continuous()
Thank you so much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
class(test$Budget)
。 R 很可能认为您的专栏是一个因素。如果是这样,您可以通过在read.csv()
内部使用stringsAsFactors
选项来解决该问题:或者为整个会话设置它:
从个人经验的话,我推荐后者。实际上,我以这种方式启动所有脚本 - 大多数需要因子的函数将根据需要强制其他向量类型,如果它们不这样做,那么我将手动指定它。但是,数据中潜藏着一堆向量只会让您头疼。
Try
class(test$Budget)
. Odds are that R believes that your column is a factor. If that's so, you can get around the problem by using thestringsAsFactors
option, either inside of yourread.csv()
:or set it for the entire session:
From personal experience, I'd recommend the latter. I start all of my scripts that way, actually - most functions that need factors will coerce other vector types as necessary, and if they don't, then I'll manually specify it. But having a bunch of vectors lurking in your data will cause you nothing but headaches.