0

I'm trying to generate weekly maps using the same data frame. Here is a sample of my data (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

And so on. I have 8k+ of data like this. This is telemetry data. So for each tower I have generated a count per hour of what tags were pinging that area. I'm creating a time lapse map to try and show movement. Ultimately, I am trying to produce a plot like this one. Older hits are orange, newer are navy.

Example Map

To generate this plot, I've used the following code:

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")

This is great, but it isn't very informative. Data is overlapping. I want to look at these maps on a weekly basis. I think I should be able to do that using the Facet_wrap function. I already have a week column in the datasheet above. However, when I add that function, I get the following error:

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

Any ideas? I can't figure out why facet_wrap isn't working. I thought it may be a gradient v discrete problem, so I tried using a discrete function of time (day) rather than a gradient. no Bueno. I'd really just love to keep my code above mostly the same, just spit out weekly maps.

thanks!

etgriffiths
  • 210
  • 2
  • 12
  • 1
    Your example works fine for me if I run your example dataset and the ggplot code (without the map). Do remove the dollar sign notation from inside `aes`, though, so things don't get mixed up. – aosmith Oct 17 '16 at 17:36
  • Good catch! Thanks. I ended up going a different way on this, but decided to leave this up for potential discuss. Here's how I moved my code, and fixed a different issue: http://stackoverflow.com/questions/40072306/datetime-limits-of-scale-color-gradient-not-working-only-when-in-for-loop-in-r – etgriffiths Oct 23 '16 at 21:55

0 Answers0