This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
library(jsonlite)
## Warning: package 'jsonlite' was built under R version 3.3.3
library("leaflet")
## Warning: package 'leaflet' was built under R version 3.3.3
setwd("H:/Data Science Johns Hopkins/Developing-Data-Product/week2")
file<-"stadiums.txt"
stadiums <- read.table(file, sep =";" , header = T ,stringsAsFactors = FALSE)
str(stadiums)
## 'data.frame': 133 obs. of 5 variables:
## $ Stadium.name: chr "Abbey Stadium" "Adams Park" "Alexandra Stadium" "Almondvale Stadium" ...
## $ Team : chr "Cambridge United" "Wycombe Wanderers" "Crewe Alexandra" "Livingston" ...
## $ Capacity : int 10847 10284 10153 10122 22374 45522 21497 10400 4000 2000 ...
## $ Latitude : num 52.2 51.6 53.1 55.9 50.9 ...
## $ Longitude : num 0.1543 -0.8003 -2.4357 -3.5221 -0.0801 ...
#Due to the "," used for thousands separator in UK R coerced the stadium capacity to string because of the coma
#so let's connvert the stadium capacity to numeric
stadiums$Capacity<-as.numeric(gsub(",", "", stadiums$Capacity))
str(stadiums)
## 'data.frame': 133 obs. of 5 variables:
## $ Stadium.name: chr "Abbey Stadium" "Adams Park" "Alexandra Stadium" "Almondvale Stadium" ...
## $ Team : chr "Cambridge United" "Wycombe Wanderers" "Crewe Alexandra" "Livingston" ...
## $ Capacity : num 10847 10284 10153 10122 22374 ...
## $ Latitude : num 52.2 51.6 53.1 55.9 50.9 ...
## $ Longitude : num 0.1543 -0.8003 -2.4357 -3.5221 -0.0801 ...
#couldn't get this part working so I stick to the circle one
footballIcon<-artIcons <- makeIcon(
iconUrl = "http://www.pngmart.com/files/1/Football-Ball-PNG.png",
iconWidth = sqrt(stadiums$Capacity)*30, iconHeight = sqrt(stadiums$Capacity)*30,
iconAnchorX = 35*215/230/2, iconAnchorY = sqrt(stadiums$Capacity)*30
)
stadiums%>%leaflet() %>%
addTiles() %>%
addCircles(weight=1 , radius= sqrt(stadiums$Capacity)*30)
## Assuming 'Longitude' and 'Latitude' are longitude and latitude, respectively
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.