Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

How can I load CSV data points onto a shapefile in R?

$
0
0

I am trying to plot Starbucks locations from CSV data onto a city shapefile that I've loaded in. I want to essentially create a heat map or simple scatter plot with the Starbucks locations on the city shapefile. The csv file has longitude and latitude points.

This is the code I have so far, I'm having trouble with merging the two files together though. Please let me know if you can help!

install.packages("sp")
install.packages("sf")

library(sf)
library(sp)

dallas_starbucks <- st_read("STREETS.shp")
st_geometry_type(dallas_starbucks)
st_crs(dallas_starbucks)
st_bbox(dallas_starbucks)
dallas_starbucks

ggplot() + 
geom_sf(data = dallas_starbucks, size = 5, color = "white", fill = "blue") +
ggtitle("Starbucks in Dallas") +
coord_sf()

starbucks_location <- read.csv("dallas_starbucks_directory.csv")
head(starbucks_locations)

----- 
dallas1 <- merge(dallas_starbucks, starbucks_location, by.x='Longitude', by.y='Latitude')

---I've also tried the PBSmapping package, but I'm stuck:

install.packages("PBSmapping")
library(PBSmapping)
sbx <- read.csv("dallas_starbucks_directory.csv")
sbx <- points(sbx$Longitude, sbx$Latitude)
library(dplyr)

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>