#' A very simple image for visualizing the classic iris dataset.
#'
#' @format A simple feature collection with 3 features and 1 field
#' \describe{
#' \item{id}{short name of flower part}
#' \item{geometry}{the sf shape corresponding to the region}
#' }
#'
#' @source \href{https://creativecommons.org/share-your-work/public-domain/cc0}{CC0} by \href{https://tkoomar.github.io}{Tanner Koomar}
#'
#' @concept toy_data
#' @family toy data sets
#' @examples
#' require(sf)
#' sf_iris <- sffs::sf_iris_simple
#' plot(sf_iris, key.length = 1, key.pos = 1)
"sf_iris_simple"
require(devtools)
require(usethis)
require(tidyverse)
require(here)
require(xml2)
require(sf)
#### Path to svg ####
### Be sure to use `here()` ###
name <- "sf_iris_simple"
input_dir <- here("data-raw", name)
input_svg <- here("data-raw", name, str_c(name, ".svg"))
sf <- paste0("svg2geojson -o ", input_svg) %>%
system(intern = TRUE) %>%
paste0(collapse = " ") %>%
st_read()
### and ensure it is valid ####
sf <- st_make_valid(sf)
#### extract geometry IDs ####
#### could also be added manually ####
xml_file <- read_xml(input_svg) %>%
xml_children()
ids <- xml_file[xml_name(xml_file) == 'path'] %>%
xml_attr('id')
sf <- sf %>%
mutate(id = ids) %>%
select(id, geometry)
#### write out the simple features ###
write_sf(sf, gsub(".svg", ".geojson", input_svg))
#### Final assignment and export of data ####
assign(name, sf)
usethis::use_data(sf_iris_simple, overwrite = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.