我想將x軸排序為1月至12月。以下是我的嘗試:
temp = structure(list(Month_Year = c("2021-01", "2021-02", "2021-03",
"2021-04", "2021-05", "2021-06", "2021-07", "2021-08", "2021-09",
"2021-10", "2021-11", "2021-12", "2022-01"), Percent = c(75,
100, 100, 98.6, 83.3, 83.3, 73.3, 83.3, 97.1, 93.1, 76.5, 100,
100), Year = c(2021, 2021, 2021, 2021, 2021, 2021, 2021, 2021,
2021, 2021, 2021, 2021, 2022), MonthN = c(1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 1), Month = c("Jan", "Feb", "Mar", "Apr", "May",
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan")), class = "data.frame", row.names = 60:72)
ggplot(temp, aes(x = Month, y = Percent, group=Year, colour=factor(Year))) +
geom_line() +
geom_point() +
labs(x="Month", colour="Year") +
theme_classic()
將月份列轉換為按正確順序設置級別的因子。在你的例子中,這可以很容易地通過
month.abb
常數實現。MonthN
列重新排序Monnth
列,即reorder(Month, MonthN)
。