Skip to content

Instantly share code, notes, and snippets.

@jshannon75 jshannon75/osmmap.R
Created Nov 15, 2019

Embed
What would you like to do?
Creating a WordCloud from OpenStreetMap in rstats using wordcloud2
library(tidyverse)
library(osmdata)
library(sf)
library(tigris)
library(wordcloud2)
library(tmap)
#Load city outline
city="Atlanta"
ga_place<-places("13",class="sf")
place<-ga_place %>%
filter(NAME==city) %>%
st_transform(4326)
#plot(place)
##Load osm points
#Key list at https://wiki.openstreetmap.org/wiki/Category:Keys
bbox_place<-st_bbox(place)
spots<-opq(bbox=bbox_place) %>%
add_osm_feature(key="cuisine") %>%
osmdata_sf()
#Select just points in the city
spots1<-spots$osm_points %>%
st_transform(4326) %>%
st_intersection(place) %>%
filter(is.na(name)==FALSE)
#Count points and select top 60
spots_count<-spots1 %>%
st_set_geometry(NULL) %>%
count(name,name="freq") %>%
rename(word=name) %>%
top_n(60)
#Plot the map--saved to PDF and imported into Illustrator
tm_shape(place)+
tm_polygons(col="#916666")+
tm_layout(frame=FALSE)+
tm_shape(spots1)+tm_dots(size=0.1)
#Create plot--used a screenshot with the map in Illustrator
wordplot<-letterCloud(spots_count,word="A",letterFont="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.