R/scale_x_long.R

Defines functions scale_x_long

#' Set Longitude label
#'
#' @description Use Longitude ºW or Longitude ºE as X axis label. For internal use in plot_telemetry()
#' @noRd
#' @keywords internal
#'
#' @details check # https://stackoverflow.com/questions/33302424/format-latitude-and-longitude-axis-labels-in-ggplot

scale_x_long <- function(xmin=-180, xmax=180, step=1, ...) {
  xbreaks <- seq(xmin,xmax,step)
  xlabels <- unlist(lapply(xbreaks, function(x) ifelse(x < 0, parse(text=paste0(x,"^o", "*W")), ifelse(x > 0, parse(text=paste0(x,"^o", "*E")),x))))
  return(scale_x_continuous("Longitude", breaks = xbreaks, labels = xlabels, expand = c(0, 0), ...))
}
machadoams/botomapr documentation built on Aug. 22, 2020, 9:44 p.m.