使用R

时间:2016-10-15 15:06:30

标签: r ggplot2 ggmap facet-wrap

我尝试使用相同的数据框生成每周地图。以下是我的数据样本(den53):

Tower  Tag_ID HourID       count  week    Lon   Lat   DateTime            day
T01    53     2016-37_6_0  167    2016-37 -94.4 42.81 2016-09-17 00:00:00 Sat
T01    53     2016-38_3_3  111    2016-38 -94.4 42.81 2016-09-21 03:00:00 Wed
T06    53     2016-38_2_22 175    2016-38 -94.5 42.82 2016-09-20 22:00:00 Thr

等等。我有8k +这样的数据。这是遥测数据。因此,对于每个塔,我每小时生成一个标记在该区域上标记的标记。我正在创建一个时间流逝图来尝试显示运动。最终,我试图制作一个像这样的情节。较旧的打击是橙色,较新的是海军。

Example Map

为了生成这个图,我使用了以下代码:

TMap + #I used ggmap for this. This is a fixed image behind the new information I am trying to plot on top of it. I'm not worried about this code.
geom_point(aes(x=Lon, y=Lat, size=count, color=as.integer(as.Date(den53$DateTime))), data=den53, alpha=1) +
scale_colour_gradient(limits=as.integer(as.Date(c(min(den53$DateTime), max(den53$DateTime)))),low="orange", high="navy", name="Time")

这很棒,但它不是很有用。数据重叠。我想每周查看这些地图。我想我应该可以使用Facet_wrap函数来做到这一点。我上面的数据表中已有一周的专栏。但是,当我添加该函数时,我收到以下错误:

TMap + 
geom_point(aes(x=Lon, y=Lat, size=count, color=as.integer(as.Date(den53$DateTime))), data=den53, alpha=1) +
scale_colour_gradient(limits=as.integer(as.Date(c(min(den53$DateTime), max(den53$DateTime)))),low="orange", high="navy", name="Time")+
facet_wrap( ~ week, ncol=2) 

Error: Aesthetics must be either length 1 or the same as the data (210): x, y

有什么想法吗?我无法弄清楚为什么facet_wrap不起作用。我认为它可能是一个渐变v离散问题,所以我尝试使用时间(日)的离散函数而不是渐变。没有布埃诺。我真的很喜欢保持我的代码大致相同,只是吐出每周地图。

谢谢!

0 个答案:

没有答案