Loading and plotting map (longitudinal and latitudinal) data

Hi,

I am working on a project with fictional data to help me learn. I have a file (source) which contains a CSV file with lon/lat information about cycling stations in the 'Divvy_Stations_2013.csv' file - I saw too there is a .shp file, however, i wanted to generate a plot from the CSV using the lon/lat data as this is what I would mostly work in (not .shp files).

I have been trying to research how I could do this and got this far - however got stuck and was looking for help and points on how I could do this. What I am trying to do is plot each row onto a long/lat chart (or map if possible?) - using this I got started with:

library(sf)
library(ggplot2)

my_sf <- st_as_sf(my_df, coords = c('LON', 'LAT')
my_sf <- st_set_crs(my_sf, crs = 4326)

#Plotting the data
ggplot(my_sf) + 
  geom_sf(aes(color = cluster))

I have not gotten as far as plotting the data yet, I get stuck with st_set_crs() as I get the error

> my_sf <- st_as_sf(my_df2, coords=c('LON', 'LAT')
+ my_sf <- st_set_crs(my_sf, crs=4326)

Error: unexpected symbol in:
"my_sf <- st_as_sf(my_df2, coords=c('LON', 'LAT')
my_sf"

I think it could be a problem with the crs="" argument -- when researching this it looks like it is a coordinate reference system to be assigned (but I am not sure what this is and if 43

This will explain how.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.