library(tidyverse)
library(sf)
library(raster)
library(spData)
library(spDataLarge)
library(tmap) # for static and interactive maps
library(leaflet) # for interactive maps
Overview
This map of Boston
is made with data from {spData}
package.
<- spData::boston.c my_df
leaflet() %>%
addProviderTiles(providers$CartoDB.Positron) %>%
setView(lng = -71.0589, lat = 42.3601, zoom = 12)
save the leaflet map as .png
library(RColorBrewer)
library(rcartocolor)
library(ggimage)
<- "#FEFCEF"
bck_color
<- "/Users/federica/Documents/R/R_general_resources/30DayMapChallenge/day4_hexagons/boston_city.png"
image
<-my_df %>%
main_plotggplot(aes(x=LON,y=LAT,group=CHAS,FILL=TRACT))+
geom_path(color="grey70",size=0.2)+
geom_hex(color="grey60",size=0.2,bins=60,alpha=0.8)+
geom_point(data=my_df,aes(x=LON,y=LAT,group=LSTAT),shape=".",color="gold",alpha=0.7)+
::scale_fill_scico(palette = "bilbao")+
scico::theme_map()
ggthemes
<-ggimage::ggbackground(main_plot, image, alpha=.7)
g g
data(us.cities)
<-us.cities%>%filter(country.etc=="MA")
marange(ma$lat)
range(ma$long)
<-us.cities%>%filter(str_detect(name,"Boston"))
boston<- subset(us.cities, capital == 2)
capitals
<- ggplot(data=capitals,aes(long, lat)) +
ma_sectionborders("state", xlim = c(-71.5, -70.08), ylim = c(41.55 ,42.5), fill = hcl.colors(286, "BrwnYl")) +
geom_hex(data=my_df,mapping=aes(x=LON,y=LAT,group=RAD),bins=90,show.legend = F)+
geom_point(boston, mapping=aes(long, lat),color="red") +
geom_point(data=my_df,aes(x=LON,y=LAT,group=LSTAT),shape=".",color="gold",alpha=0.4)+
::scale_fill_carto_c(type = "diverging", palette = "Fall", direction = -1)+
rcartocolorcoord_quickmap()+
theme_nothing()+
theme(plot.background = element_rect(fill="grey80",color="grey80"),
panel.background = element_rect(fill="grey80",color="grey80"))
<-ma_section+
ma_sectiontheme_gray()+
theme(axis.text = element_blank(),
axis.ticks = element_blank(),
axis.title = element_blank(),
plot.background = element_rect(fill="grey95",color="grey80"),
panel.grid.major.x = element_blank())
# save final plot
::agg_png(here::here("~/Documents/R/R_general_resources/30DayMapChallenge/day4_hexagons/ma_section.png"),
raggres = 320, width = 12, height = 8.5, units = "in")
ma_sectiondev.off()
library(extrafont)
loadfonts()
fonts()
<- "Scooby Doo"
family# final touches
library(cowplot)
library(magick)
<- magick::image_read("~/Documents/R/R_general_resources/30DayMapChallenge/day4_hexagons/ma_section.png")
image_ma_section
<- magick::image_read("~/Documents/R/R_general_resources/30DayMapChallenge/day4_hexagons/boston_symbol.png")
image_boston_sym
<- cowplot::ggdraw(g)+
final draw_image(image_ma_section,x = 0.05, y = -0.41,width = 0.15)+
draw_image(image_boston_sym,x = 0.008, y = 0.42,width = 0.08)+
draw_label(label="Datasource: {spData} Boston.c\nInfographic: Federica Gazzelloni",x=0.5,y=0.05, fontfamily = family) +
draw_label(label="Boston city lower status population\npercentage values",x=0.45,y=0.93, fontfamily = family,size=30)
# save final plot
::agg_png("~/Documents/R/R_general_resources/30DayMapChallenge/day4_hexagons/hexagons.png",
raggres = 320, width = 12, height = 8.5, units = "in")
finaldev.off()