2016-09-22 100 views
-2

我有下面的数据,并且正在尝试绘制月份VS面积的散点图。如何绘制散点图(月vs面积)

Month Area 
feb 13.05 
oct 13.7 
mar 13.99 
sep 14.57 
aug 15.45 
sep 17.2 
sep 19.23 
sep 23.41 
oct 24.23 
aug 26 
sep 26.13 
mar 27.35 

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

Area VS Month

+0

我想我没有正确发布的数据。它是类似的。月份\t区域 feb \t 13.05; oct \t 13.7; mar \t 13.99; sep \t 14.57; aug \t 15.45; sep \t 17.2; sep \t 19.23; sep \t 23.41; oct \t 24.23; aug \t 26; sep \t 26.13; mar \t 27.35; – RMaddy

+1

编辑器中提供了编辑工具 - 我们在这里使用Markdown,并且在提交之前有一个预览窗口以确保您的文章可以正常工作。你还会解释为什么ggplot2不能满足你的需求吗?读者一般喜欢在这里看到一个尝试。 – halfer

回答

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