我有一個如下所示的CSV文件。如何在數據框中將月份更改爲月份?
year=c("2015","2016","2017")
month=c("1","2","3","4","5","6","7","8","9","10","11","12")
freq=c("10","12","16","12","21","16","23","22","20","19","21","15")
df=data.frame(year, month, freq)
ggplot(df, aes(x=month, y=freq, fill=year))+geom_bar(stat="identity)
axis.x顯示1,10,11,12,2,3,4,5,6,7,8,9
我想1,2,3,4,5,6,7,8,9,10,11,12
我該怎麼辦?
不要存儲數字串。在這種情況下,不幸的是字符串被'data.frame'轉換爲因子,所以你需要做'df $ month < - as.integer(as.character(df $ month))'使它們回到整數,儘管從數字開始顯然更好。你的其他專欄也一樣。 – alistaire
這不是一個CSV文件,你是從矢量創建一個數據框。你的真實代碼是否讀取一個文件? – neilfws