r - Using ggplot2, connect x- and y-coordinates by a third variable -


i plot latitude vs longitude , connect points via date , time, have stored in object of class posixlt. have many, many gps points, here small set of them plot using ggplot2.

my data so:

description             lat         lon 6/16/2012 17:22         12.117017   -89.69692 6/17/2012 9:15          12.1178     -89.69675 6/17/2012 9:33          12.117783   -89.69673 6/17/2012 10:19         12.11785    -89.69665 6/17/2012 10:45         12.11775    -89.69677 6/17/2012 11:22         12.1178     -89.69673 6/17/2012 11:39         12.117817   -89.69662 6/17/2012 11:59         12.117717   -89.69677 6/17/2012 12:10         12.117717   -89.69655 6/16/2012 16:38         12.11795    -89.6965 6/16/2012 18:29         12.1178     -89.69688 6/16/2012 17:11         12.117417   -89.69703 6/16/2012 17:36         12.116967   -89.69668 6/16/2012 17:50         12.117217   -89.69695 6/16/2012 18:02         12.117583   -89.69715 6/16/2012 18:15         12.11785    -89.69665 6/16/2012 18:27         12.117683   -89.69632 

i have map plotting these points onto.

i can plot points fine

plot1 <- map + geom_point(data=dat, aes(x = lon, y  = lat))   

map object made ggmap, it's not important include here. following code produces line connecting points lon increases

plot1+geom_line(data=dat, aes(x=lon,y=lat,colour="red")) 

i can't figure out how connect points vector posixlt object description know in small example reorder points using dat2 <- dat[with(dat, order(description)), ], , remake plot1 using dat2 , make desired plot using following code:

plot1+geom_path(data=dat2, aes(x = lond, y  = latd, colour="red")) 

but larger (hundreds of thousands of observations) dataset, doesn't make sense solution without bit more work id each observation, end doing anyway part of additional data exploration. there argument haven't discovered in geom_line telling r how connect points?

i admittedly still novice @ using ggplot2, , so, apologize if have missed simple. have been working on lot of other code , learning, or @ least using, several other packages, work gps data other spatial data available. it's bit overwhelming... many ideas, little know-how! larger point of visualize (and analyze) movement patterns , use of space study organisms, now, great visualize data in variety of ways familiar it.

if have recommended packages working spatial data , gps data, i'd love hear them, well.

you need rows ordered date/time object use geom_path. since think best way display data should focus on finding efficient way sort large dataset. idea of scale of dataset working with. millions of rows? billions perhaps?!

fortunately data.table package indeed. here example on 1 million row table, id column x, table sorted on, unsorted time column of 1 second observations, , 2 random columns x , y, takes < 1s on laptop t sort according date/time:

set.seed(123) require(data.table)  #  rows ordered on x, random order of unique date/time values of 1 second observations df <- data.frame( id = seq.int(1e6) , desc = as.posixct(sample(1e6),origin=sys.date()) , x = runif(1e6) , y = runif(1e6) ) head(df) #  id                desc         x         y #1  1 2013-05-25 02:39:39 0.2363783 0.1387404 #2  2 2013-05-25 23:58:17 0.1192702 0.1284918 #3  3 2013-05-21 17:41:57 0.8599183 0.6301114 #4  4 2013-05-23 16:12:42 0.8089243 0.7919304 #5  5 2013-05-21 08:17:28 0.8197109 0.4568693 #6  6 2013-05-22 17:57:23 0.4611204 0.5358536 #  convert data.table dt <- data.table(df)  #  sort on 'desc' setkey(dt , desc) head(dt) #          id                desc         x          y #1: 544945 2013-05-18 01:00:01 0.7052422 0.52030877 #2: 886165 2013-05-18 01:00:02 0.2256636 0.04391553 #3: 893690 2013-05-18 01:00:03 0.1860687 0.30978506 #4: 932276 2013-05-18 01:00:04 0.6305562 0.65188810 #5: 407622 2013-05-18 01:00:05 0.5355992 0.98146120 #6: 138936 2013-05-18 01:00:06 0.5999025 0.81722902   #  make data.frame use ggplot2 (not sure if can't use data.table directly) df2 <- dt 

so in case can try like:

datdt <- data.table(dat) setkey(datdt , description) dat2 <- datdt 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -