首页 > 解决方案 > 我的 ggplot 折线图上的日期没有排序

问题描述

我有从 3 月 10 日到 5 月 14 日的数据,但 x 轴没有按给定的顺序绘制。 在此处输入图像描述

rm(list = ls())

ahm <- read.csv("PM2.5.csv")
View(ahm)
ggplot(ahm, aes(x=date, group = 1)) + 
  geom_line(aes(y = X2019), color = "darkred", size = 1) +
  geom_smooth(data=ahm, formula= y ~ x,method= "loess", aes(x = date, y = X2019,group=1)) +
  geom_line(aes(y = X2020), color = "steelblue", size = 1) +
  geom_smooth(data=ahm, formula= y ~ x,method= "loess", aes(x = date, y = X2020,group=1)) +
  geom_line(aes(y = X2021), color = "green", size = 1) +
  geom_smooth(data=ahm, formula= y ~ x,method= "loess", aes(x = date, y = X2021,group=1)) +
  labs(x= "Date", y="Concentration", title= "Ahmedabad PM2.5") +
  theme(axis.text.x = element_text(angle = 90))

标签: rggplot2

解决方案


推荐阅读