This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.6 ✓ purrr 0.3.4
## ✓ tibble 3.1.6 ✓ dplyr 1.0.8
## ✓ tidyr 1.2.0 ✓ stringr 1.4.0
## ✓ readr 2.1.2 ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(sf)
## Linking to GEOS 3.10.2, GDAL 3.4.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(maps)
##
## Attaching package: 'maps'
## The following object is masked from 'package:purrr':
##
## map
library(leaflet)
library(rnaturalearthdata)
brazil_sf <- countries110 %>%
st_as_sf() %>%
filter(name == "Brazil")
brazil_cities <- world.cities %>%
filter(country.etc == "Brazil",
pop >= 1E6) %>%
st_as_sf(coords = c("long", "lat"), crs = 4326) %>%
arrange(desc(pop))
leaflet() %>%
addPolygons(data = brazil_sf,
fillColor = "darkolivegreen",
fillOpacity = 1,
color = "black",
weight = 1
) %>%
addCircleMarkers(data = brazil_cities,
label = ~name)
## Warning: sf layer has inconsistent datum (+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs).
## Need '+proj=longlat +datum=WGS84'
leaflet() %>%
addPolygons(data = brazil_sf,
fillColor = "darkolivegreen",
fillOpacity = 1,
color = "black",
weight = 1
) %>%
addCircleMarkers(data = brazil_cities,
popup = ~paste(name, pop))
## Warning: sf layer has inconsistent datum (+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs).
## Need '+proj=longlat +datum=WGS84'
leaflet() %>%
addPolygons(data = brazil_sf,
fillColor = "darkolivegreen",
fillOpacity = 1,
color = "black",
weight = 1
) %>%
addCircleMarkers(data = brazil_cities,
label = ~country.etc,
popup = ~paste(name, pop))
## Warning: sf layer has inconsistent datum (+proj=longlat +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +no_defs).
## Need '+proj=longlat +datum=WGS84'