--- title: "Transform Data" description: "Move longitude/latitude data into the same projection and inset layout used by jpmap maps." output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{Transform Data} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- ```{r, include = FALSE} knitr::opts_chunk$set(collapse = TRUE, comment = "#>", message = FALSE) ``` `jpmap_transform()` moves user data into the same projected coordinate system used by `plot_jpmap()`. ## Data Frames ```{r} library(tidyverse) library(jpmap) places <- tribble( ~place, ~lon, ~lat, "Tokyo", 139.767, 35.681, "Naha", 127.681, 26.212, "Ogasawara", 142.191, 27.094 ) places |> jpmap_transform(output_names = c("x", "y")) ``` ## Simple Features If `data` is an `sf` object, `jpmap_transform()` returns an `sf` object. ```{r} pts <- sf::st_as_sf( places, coords = c("lon", "lat"), crs = 4326, remove = FALSE ) pts |> jpmap_transform() ``` Use `inset = FALSE` when you want only the projected Japan CRS and not the Okinawa/Ogasawara inset movement. ```{r} places |> jpmap_transform(output_names = c("x", "y"), inset = FALSE) ``` You can also move only one island group. ```{r} places |> jpmap_transform(output_names = c("x", "y"), inset = "okinawa") places |> jpmap_transform(output_names = c("x", "y"), inset = "ogasawara") ``` The same switches can be written as boolean arguments when you want the default `inset = TRUE` behavior except for one island group. ```{r} places |> jpmap_transform(output_names = c("x", "y"), okinawa = FALSE) places |> jpmap_transform(output_names = c("x", "y"), ogasawara = FALSE) ```