working with csv data- creating point maps using leaflet R package in rstudio

This post intends to demonstrate how to deploy point data in CSV format to create web maps using the leaflet R package.

Prepare your CSV data so that the location fields (Y) and (X) should be titled long and lat. This would make it easier for the leaflet R package to recognize them as location fields.

1. Launch RStudio and choose the Packages tab. Check the raster and leaflet package boxes.

image

2. Once the packages are activated in the window console, type in the read.csv command to load the CSV file from the local directory. Hit the Enter key to run the command.

image

3. The CSV file is added to the Environment window as seen in the screenshot example below.

image

4. Next we write out the codes to initialize the leaflet map, add base tiles and add the CSV data as markers on the base map.

leaflet( data = poi) %>%       //load the data into leaflet map

addTiles() %>%                  //add base tiles

addMarkers(~long, ~lat)   //add the data as markers on the base map using the values in         their long and lat colums

image

5. Click on the viewer tab and preview the leaflet map.

image

6. Next we convert the markers from the default to circles form by using addcircleMarkers() instead of addMarkers()

image

image

7. Go to the viewer tab and preview the leaflet map.

image

Thank you for following the blog.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s