Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I wanted to plot the data frame on google maps since I already have an account in google API. But I have lost may resource without my knowledge. I got the long and latit by using the geocode() as shown below:

The variables are: Program, Credits, Univ, Location, lon, lat

     Program

2                Master's Programme in Data Science - Data Engineering

3                                       Data Science: Master programme

4                                    Data Science - Master's Programme

5                                    Data Science - Master's Programme

6                                     Master Programme in Data Science

8 Master's Programme in Data Science - Machine Learning and Statistics

  Credits                           Univ Location      lon      lat

2     120             Uppsala University  Uppsala 17.63893 59.85856

3     120             Dalarna University Borlänge 15.43397 60.48430

4     120           University of Skövde   Skövde 13.84612 58.39028

5      60           University of Skövde   Skövde 13.84612 58.39028

6      60 Luleå University of Technology    Luleå 22.15670 65.58482

8     120             Uppsala University  Uppsala 17.63893 59.85856

1 Answer

0 votes
by (36.8k points)

As per my knowledge leaflet can be used and plot the points over the OpenStreetMap layer. This package needs API or linked account:

# Packages

library(dplyr) # to use the pipe operator (magrittr can be used too)

library(leaflet) # acces to openstreetmap layer

library(htmltools) # label each point

# Data

data <-  structure(list(

    Univ.location = c( "Uppsala University  Uppsala",

       "Dalarna University Borlänge", "University of Skövde   Skövde", 

       "University of Skövde   Skövde", "University of Technology    Luleå", 

       "Uppsala University  Uppsala"),

    lon = c(17.63893, 15.43397, 13.84612, 

             13.84612, 22.1567, 17.63893),

    lat = c(59.85856, 60.4843, 58.39028, 

           58.39028, 65.58482, 59.85856)),

    class = "data.frame", row.names = c(NA, -6L))

# Map

data %>% 

    leaflet() %>% 

    addTiles() %>% 

    addCircleMarkers( label = ~htmlEscape(Univ.location))

If you are a beginner and want to know more about Data Science the do check out the Data Science course 

Browse Categories

...