For Turkish click

Recently, Izmir Metropolitan Municipality announced the foundation of the Open Data Platfrom. Thereby, They make a contribution to the both data literature for Turkey and the management mechanism in Local Authorities. Izmir also becomes the second Metropolitan Municipality in Turkey having a open data platform.

Here, I use the dataset of subway stations in Izmir and create a map using Leaflet in R.

To download the data.

For leaflet tutorial.

Read the data set first.

d<-read.csv("metro-istasyonlar.csv",header=T,sep=";")
head(d)
##   ï..Ä.stasyon.Id     Ä.stasyon.AdÄ. Ä.stasyon.SÄ.rasÄ. AktifMi Longitude
## 1              12           Evka - 3                  1    True   27.2289
## 2              11  Ege Ãœniversitesi                  2    True   27.2283
## 3              10            Bornova                  3    True   27.2128
## 4               9             Bölge                  4    True   27.2008
## 5               8             Sanayi                  5    True   27.1900
## 6               7            Stadyum                  6    True   27.1808
##   Latitude
## 1  38.4656
## 2  38.4600
## 3  38.4586
## 4  38.4547
## 5  38.4481
## 6  38.4425

Although we suffer from the character problems, since we are interested in only lat and long values, we do not care about this situation.

After reading the dataset, let’s create a Izmir map via leaflet package. To do so, we need the long and lat values for Izmir, which are 27.142826 and 38.423733, respectively.

Now, we can create our plots using only three code.

The first one is the leaflet() which creates a Leaflep map using htmlwidges. Then, we combine this with pipe opertor to the second code which is setView() . This is used to set the location of the map. Finally, we add tiles by typing addTiles() which adds graphical elements and layers.

Here is the Izmir Map.

library(leaflet)
## Warning: package 'leaflet' was built under R version 3.6.3
leaflet()%>%setView(lng=27.142826, lat=38.423733, zoom=11)%>%addTiles()

Then, we add location icon for the place of the station on the map using addMarkers function.

For this process, we only set lng and lat arguments in the function to the lat and long values where each corresponds to the subway station.

Please be careful! Our lat and long values must be numeric class.

This is the result, it looks like a plot representing a pure linear relationship huh?

leaflet()%>%setView(lng=27.142826, lat=38.423733, zoom=11)%>%addTiles()%>%addMarkers(lng=as.numeric(d$Longitude), lat= as.numeric(d$Latitude))

Here is the GitHub

Questions, opinions and suggestions: