Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

easy trip constructors #21

Closed
mdsumner opened this issue May 23, 2017 · 5 comments
Closed

easy trip constructors #21

mdsumner opened this issue May 23, 2017 · 5 comments

Comments

@mdsumner
Copy link
Member

This is completely hopeless as a way of working:

chunk <- 500
tab <- tbl(db, "Tracking") %>% 
   arrange/distinct/mutate/rename etc. 

## 3 points don't make it
tab <- tab %>% group_by(ID) %>% filter(n() > 3) %>% ungroup() %>% as.data.frame()
## shouldn't have to make a copy
  tr <- tab
## needs to be elevated unjoin(tr, c("x", "y")) or aes(x, y)
  coordinates(tr) <- c("x", "y")
## again, shouldn't be so awkward
  proj4string(tr) <- "+init=epsg:4326"
## I constantly forget which way so  aes(x, y, time = gmt, id = ID) or unjoin(x, y, time, id)
  tr <- trip(tr, c("gmt", "ID"))
## bespoke filter idiom e.g. filter(speedfilter(x, y, gmt))  ?
  tr <- tr[speedfilter(tr, max.speed = max_speed), ]
## at least allow trip to work with tibble
  tab <- as.data.frame(tr) %>% as_tibble()

Make some easy improvements to help using trip with the current functionality.

@mdsumner
Copy link
Member Author

mdsumner commented Jun 16, 2017

Early stab here:

https://github.com/Trackage/trip/blob/aes/R/gg-aesthetics.R

Still need:

  • maintenance of original names to round trip sp
  • optional use of x/y, allow default as first two
  • consider longitude = , latitude = as more explicit nomination over x/y ?
  • apply grouping and arrangement tests with dplyr of trip-validity
  • consider unjoin as a way of maintaining original state, duplicated records, duplicated times, missing coords/identifiers etc.

@mdsumner
Copy link
Member Author

mdsumner commented Apr 5, 2019

I think this is waaay better, also toying with rlang approach to catpure trip(data, x, y, t, g, ...) as the column names.

trip.grouped_df <- function(obj, ..., crs = NULL) {
   tor <- c(names(obj)[3], dplyr::group_vars(obj))
   if (!inherits(obj[[tor[1]]], "POSIXct")) stop(sprintf("3rd column [%s] must be date-time", tor[1]))
   obj <- dplyr::ungroup(obj)
   sp::coordinates(obj) <- names(obj)[1:2]
   if (!is.null(crs)) sp::proj4string(obj)
   trip(obj, tor)
}


library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(trip)
#> Loading required package: sp

d <- tibble::as_tibble(walrus818)
d <- d %>% group_by(Deployment)
d <- d %>% select(X_AED170_70,Y_AED170_70, DataDT, everything())
tr <- trip.grouped_df(d)

## the really neat part is that this grouped data frame is directly useable with
## ggplot2 as-is
library(ggplot2)
ggplot(d, aes(X_AED170_70, Y_AED170_70, col = DataDT)) + geom_path()

Created on 2019-04-05 by the reprex package (v0.2.1)

@mdsumner mdsumner changed the title new idioms easy trip constructors Apr 5, 2019
@mdsumner
Copy link
Member Author

mdsumner commented Apr 6, 2019

@mdsumner
Copy link
Member Author

This is done!

  • trip(x) where x is a data frame x, y, time, id, whatever
  • trip(x) where x is a groupd_ed x, y, time

Also added mousetrap, amt and trackeR support see #29

@mdsumner
Copy link
Member Author

thanks @ianjonsen ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant