如何绘制散点图(月份与面积)

时间:2016-09-22 16:37:08

标签: r ggplot2 scatter

我有以下数据,我正在尝试为T VS Month绘制散点图。

Area

当我绘制散点图时,绘图类似于附加图像。我想要做的是按时间顺序(1月至12月)按顺序绘制x轴。我尝试使用ggplot2,但我无法这样做。

Area VS Month

1 个答案:

答案 0 :(得分:0)

R不会自动知道您提供的数据类型。系统知道“feb”与“the”没有什么不同,所以如果你想要一些特别的东西(比如日期),你需要告诉系统这样做。

例如:

monthData$cleanMonth <-
  as.Date(paste0("2016-",monthData$Month,"-01")
          , format = "%Y-%b-%d")

ggplot(monthData
       , aes(x = cleanMonth
             , y = Area)) +
  geom_point() +
  scale_x_date(date_breaks = "1 month"
               , date_labels = "%b")

enter image description here