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(leaflet)
## Warning: package 'leaflet' was built under R version 4.0.3
Loyola <- c(39.3463882,-76.6210078, "College", 4000)
Hopkins <- c(39.3297084,-76.6219169, "College", 18000)
Alonsos <- c(39.3445304,-76.6308260, "Bar", 1000)
gps_df <- data.frame(rbind(Loyola, Hopkins, Alonsos))
colnames(gps_df) <- c("Lat", "Long", "Type", "n")
gps_df$Lat <- as.numeric(gps_df$Lat)
gps_df$Long <- as.numeric(gps_df$Long)
gps_df$n <- as.numeric(gps_df$n)
m <- leaflet() %>%
addProviderTiles(providers$Wikimedia) %>%
setView(lng = -76.6308260, lat = 39.3445304, zoom = 12 ) %>%
addCircles(
lng = subset(gps_df, Type == 'College')$Long,
lat = subset(gps_df, Type == 'College')$Lat,
opacity=10,
color="red",
popup = paste(row.names(subset(gps_df, Type == 'College')), subset(gps_df, Type == 'College')$n),
radius = sqrt(subset(gps_df, Type == 'College')$n)
) %>%
addCircles(
lng = subset(gps_df, Type == 'Bar')$Long,
lat = subset(gps_df, Type == 'Bar')$Lat,
opacity=10,
color="blue",
popup = paste(row.names(subset(gps_df, Type == 'Bar')), subset(gps_df, Type == 'Bar')$n),
radius = 40
)
setwd("C:/Users/pptallon/Dropbox/G/Teaching/Data Visualization Data Files")
htmltools::includeHTML("BaltimoreMap.html")
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.