I had found a cool website that generates random data for free with no signups and thought it would be perfect for this kinda project.
library(sp)
## Warning: package 'sp' was built under R version 3.6.3
library(leaflet)
## Warning: package 'leaflet' was built under R version 3.6.3
data <- read.csv("C:/Users/user/Downloads/MOCK_DATA.csv")
str(data)
## 'data.frame': 1000 obs. of 10 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ first_name: Factor w/ 949 levels "Ab","Abbey","Abbot",..: 337 238 269 357 10 821 868 453 350 881 ...
## $ last_name : Factor w/ 987 levels "Abdee","Abramino",..: 427 262 937 127 22 218 334 980 798 875 ...
## $ email : Factor w/ 1000 levels "aabdeen0@goo.gl",..: 368 250 292 356 6 865 929 491 383 951 ...
## $ gender : Factor w/ 2 levels "Female","Male": 1 2 1 1 2 1 1 2 1 2 ...
## $ ip_address: Factor w/ 1000 levels "0.44.211.99",..: 545 114 992 581 359 905 672 32 361 856 ...
## $ city : Factor w/ 987 levels "Örebro","Östersund",..: 566 222 125 212 171 915 689 903 850 383 ...
## $ lat : num 11.6 54.4 45.1 47 25.3 ...
## $ long : num 124.4 24.33 3.81 129.02 110.3 ...
## $ income : Factor w/ 1000 levels "$100046.34","$100176.74",..: 919 423 90 951 193 647 209 948 650 131 ...
data1 <- data[complete.cases(data),]
data1<-data1[!is.na(data1$long)&!is.na(data1$lat),]
str(data1)
## 'data.frame': 1000 obs. of 10 variables:
## $ id : int 1 2 3 4 5 6 7 8 9 10 ...
## $ first_name: Factor w/ 949 levels "Ab","Abbey","Abbot",..: 337 238 269 357 10 821 868 453 350 881 ...
## $ last_name : Factor w/ 987 levels "Abdee","Abramino",..: 427 262 937 127 22 218 334 980 798 875 ...
## $ email : Factor w/ 1000 levels "aabdeen0@goo.gl",..: 368 250 292 356 6 865 929 491 383 951 ...
## $ gender : Factor w/ 2 levels "Female","Male": 1 2 1 1 2 1 1 2 1 2 ...
## $ ip_address: Factor w/ 1000 levels "0.44.211.99",..: 545 114 992 581 359 905 672 32 361 856 ...
## $ city : Factor w/ 987 levels "Örebro","Östersund",..: 566 222 125 212 171 915 689 903 850 383 ...
## $ lat : num 11.6 54.4 45.1 47 25.3 ...
## $ long : num 124.4 24.33 3.81 129.02 110.3 ...
## $ income : Factor w/ 1000 levels "$100046.34","$100176.74",..: 919 423 90 951 193 647 209 948 650 131 ...
Since no observations were issued missing or NA I went ahead and used the original data for the rest of the assignment.
Even though the data is mock data, it still felt creepy to display information about robo-people on an interactive map. The least obtrusive data to display was thier income which is very respectable.
data$long <- as.numeric(data$long)
data$lat <- as.numeric(data$lat)
#data.SP <- SpatialPointsDataFrame(data[,c(8,9)], data[,-c(8,9)])
map <- leaflet() %>%
addTiles() %>%
addMarkers(data = data, lng = ~long, lat = ~lat, popup = ~income, clusterOptions = markerClusterOptions())
map