绘制与ggplot
问题描述:
月度数据我试图用ggplot绘制看起来像这样绘制与ggplot
count date 6 Oct 2010 23 Nov 2010 20 Dec 2010 16 Jan 2011 64 Oct 2011 ... 425 Jul 2012 436 Aug 2012 405 Sep 2012
其中date是yearmon类从动物园套餐月的数据。
这是我的电话:
ggplot(data, aes(x=date, y=count))+geom_line()
这个错误想出了:错误:提供给连续的尺度离散值。
所以ggplot不支持yearmon类,这很好。
然后我尝试将yearmon转换为Date。现在的数据是这样的:
count date 6 2010-10-01 23 2010-11-01 20 2010-12-01 16 2011-01-01 64 2011-10-01 ... 425 2012-07-01 436 2012-08-01 405 2012-09-01
和我做同样的呼吁,这是 the resulting plot(约在href对不起......新用户不得发表图片)
有一个因为数据$ count在最后几行具有相似的值,所以不应该出现在该图的末尾。
有没有人有一个很好的解决方案呢?
感谢您的阅读,
比尔
答
我无法重新创建具有行上图的右侧出人意料地下降的问题。下面是我使用的代码,输出:
library(ggplot2)
dat = read.table(header=TRUE, colClasses=c("numeric", "Date"),
text=" count date
6 2010-10-01
23 2010-11-01
20 2010-12-01
16 2011-01-01
64 2011-10-01
425 2012-07-01
436 2012-08-01
405 2012-09-01")
plot_1 = ggplot(dat, aes(x=date, y=count)) + geom_line()
ggsave("plot_1.png", plot_1, height=4.5, width=4.5)
你可能会考虑(使用dput()
),以帮助人们重现你的问题之前和之后的日期转换可以发布您的数据。
感谢您检查此事。它确实成为SQL数据库上的数据的问题。我没有注意到有些记录被删除,10月份的更新被碰撞到中间。新手错误。谢谢你的时间。 –
不客气,很高兴你知道了! – bdemarest