我正在嘗試將多個時間序列繪制成單個圖形,如所附影像,但我收到此錯誤Error: Invalid input: date_trans works with objects of class Date only。date
我試圖通過使用lubricate
包或我在互聯網上找到的其他方法將包含月份的列轉換為格式來解決這個問題。這是資料:
structure(list(Month = c("2016-01-01", "2016-02-01", "2016-03-01",
"2016-04-01", "2016-05-01", "2016-10-01", "2016-11-01", "2016-12-01"
), Residential = c(36.22021, 40.31832, 37.83721, 39.75821, 34.7028,
42.97021, 37.61029, 41.58934), Residential.Informal = c(33.3279,
35.2452, 34.67857, 30.44121, 30.65073, 35.55425, 34.04282, 35.22392
), Non.Residential = c(79.75459, 80.79518, 96.62088, 95.32751,
94.49208, 91.24384, 115.131, 119.9929)), class = "data.frame", row.names = c(NA,
-8L))
這是代碼,其中沒有我所有的嘗試和錯誤:
df <- read.csv("wd/ts_all_month.csv")
df_melt = melt(df, id.vars = 'Month')
#multiple ts plots
tiff("ts_lu.tiff", units="in", width=14, height=8, res=300)
ggplot(df_melt, aes(x = Month, y = value))
geom_line()
facet_wrap(~ variable, scales = 'free_y', ncol = 1)
dev.off()
uj5u.com熱心網友回復:
使用您的示例資料,您可以執行以下操作:
ggplot(df_melt, aes(x = Month, y = value))
geom_line()
facet_wrap(~ variable, scales = 'free_y', ncol = 1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/471590.html
上一篇:如何使用ggplot和ggalluvial正確地用數字標記地層?
下一篇:用戶選擇主題R閃亮的ggplot