R/add_carts.R

Defines functions add_carts

Documented in add_carts

#' add_carts
#' @name add_carts
#' @description Adding cartesian coordinates to test results
#' @param data Data frame, ideally output from [read_maia_tgz].
#' @param digits how precise to be about eccentricity and angles
#' @return Data frames
#' @details
#' if not using output from read_maia_tgz, the data frame needs to contain a
#' column called "angle" (angle given in radians) and "eccent" (eccentricity given in any unit)
#' @family prediction functions
#' @export
add_carts <- function(data, digits = 2) {
  data_coord <- data %>%
  mutate(
    x = round(cos(.data$angle * pi / 180) * as.numeric(.data$eccent), digits = digits),
    y = round(sin(.data$angle * pi / 180) * as.numeric(.data$eccent), digits = digits)
  )
return(data_coord)
}

## for plotting function
# test_d <- filter(test, testDate>"2020-01-01") %>%
#   add_carts()
# ggplot(test, aes(x,y)) +
#   geom_point()
tjebo/maiaR documentation built on Feb. 11, 2024, 4:22 p.m.