在R中获取barplot而不是scatterplot

时间:2014-08-22 16:45:04

标签: r

我尝试从具有以下前8行的数据框(plot)中df

df = 

V1  V2  V3
1   34.62365962451697   78.0246928153624    0
2   30.28671076822607   43.89499752400101   0
3   35.84740876993872   72.90219802708364   0
4   60.18259938620976   86.30855209546826   1
5   79.0327360507101    75.3443764369103    1
6   45.08327747668339   56.3163717815305    0
7   61.10666453684766   96.51142588489624   1
8   75.02474556738889   46.55401354116538   1

我使用plot(df$V1, df$V2),但我得到的是这张图片: R-plot

当我使用plot(df)时,它会向我显示正确的结果,如下图所示。

R-scatterplot

我在这里缺少什么?

1 个答案:

答案 0 :(得分:2)

您的专栏是因素。在您读入数据时,添加选项colClasses = rep("numeric", 3)或将其应用于您当前的data.frame df = data.frame(apply(df, 2, function(x) as.numeric(as.character(x))))