开发者

Non-continuous variable supplied to scale_x_continuous in ggplot2 geom_point graph

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


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 the stringsAsFactors option, either inside of your read.csv():

test <- read.csv(file = "yourdata.csv", stringsAsFactors = FALSE)

or set it for the entire session:

options(stringsAsFactors = FALSE)

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜