Generating a dataset (coordinates + informations about the schools)

Each school contains its:
- full name,
- studying level,
- address,
- number of teachers,
- year of creation,
- coordinates (to set points on map)

wwk_coordinates <- c(52.66, 19.067)

schools <- c("LZK", "LMK", "IILO", "SP8", "ZS4", "SP23", "ZSEl", "ZST", "KSW", "PANS", "ZSCh", "ZSE", "SP3", "SP22")

full_names <- c("I high school for them Kuyavian land in Włocławek",
                "III high school for them Maria Skłodowska Curie in Włocławek",
                "II High School for them Nicolaus Copernicus in Włocławek",
                "Primary school no. 8 for them 3rd Warsaw Pontoon Regiment in Włocławek",
                "School Complex No. 4 for them Krzysztof Kamil Baczyński in Włocławek",
                "Primary school no. 23 for them cardinal S. Wyszyński in Włocławek",
                "Electrical school complex in Włocławek",
                "Technical school complex in Włocławek",
                "Kuyavian High School in Włocławek",
                "State Academy of Applied Sciences in Włocławek",
                "Chemical school complex in Włocławek for them M. Curie in Włocławek",
                "Economic school complex in Włocławek",
                "Primary school no. 3 for them Pope John Paul II in Włocławek",
                "Primary school no. 3 for them Janusz Korczak in Włocławek")

levels <- c("high school", "high school", "high school", "primary school", "high school", "primary school", "high school", "high school", "university", "university", "high school", "high school", "primary school", "primary school")

addresses <- c("Mickiewicza 6, 87-800 Włocławek",
               "Stanisława Bechiego 1, 87-800 Włocławek",
               "Urocza 3, 87-800 Włocławek",
               "Willowa 8, 87-800 Włocławek",
               "Kaliska 108, 87-800 Włocławek",
               "Stanisława Wyspiańskiego 3, 87-800 Włocławek",
               "Toruńska 77/83, 87-822 Włocławek",
               "Ogniowa 2, 87-800 Włocławek",
               "Stefana Okrzei 94, 87-800 Włocławek",
               "Energetyków 30, 87-800 Włocławek",
               "Bulwary im. marsz. Piłsudskiego 4, 87-800 Włocławek",
               "Bukowa 38, 87-800 Włocławek",
               "Cyganka 6, 87-800 Włocławek",
               "Promienna 15, 87-816 Włocławek"
               )

teachers_counts <- c(63, 76, 51, 52, 61, 33, 49, 58, 48, 61, 43, 63, 38, 61)

creation_years <- c(1900, 1918, 1959, 1923, 1985, 1956, 1974, 1920, 1995, 2002, 1989, 1974, 1973, 1985)

latitudes <- c(52.656881455150675, 52.65829674842552, 52.66424045, 52.6730652, 52.637450694515664, 52.64616475, 52.6679162, 52.6578533, 52.6629116, 52.66799775, 52.6576791, 52.65174355, 52.658535799999996, 52.66786345)

longitudes <- c(19.06339587295932, 19.077987790500714, 19.03788232548714, 19.0677289, 19.045950961221997, 19.036912150000003, 19.043436, 19.07986369572201, 19.057136548729147, 19.040979464893624, 19.08152811403508, 19.071508661857024, 19.07254843859485, 19.036201914204597)

wwk_schools_df <- data.frame(
  shortcut = schools,
  full_names = full_names,
  levels = levels,
  addresses = addresses,
  techaers_counts = teachers_counts,
  creations_years = creation_years,
  lat = latitudes,
  long = longitudes
)

Creating a custom icon to be displayed differently depending on the school’s studying level

icon <- awesomeIcons(
  icon = 'university',
  iconColor = 'black',
  library = 'ion',
  markerColor = ifelse(wwk_schools_df$levels == 'primary school', 'green', ifelse(wwk_schools_df$levels == 'high school', 'blue', 'orange')))

Generating a leaflet map including

  1. Setting default view on the chosen town: Włocławek
  2. Creating a leaflet map including 14 of different schools located in Włocławek
  3. Each school is indicated as a point on the map
  4. Depending on the studying level, every point has different color (legend shows which level correspond to which color)
  5. Ater clicking on each point, all the remaining data about the school is displayed
leaflet() %>%
  setView(lng = wwk_coordinates[2], lat = wwk_coordinates[1], zoom = 13) %>%
  addTiles() %>%
  addAwesomeMarkers(
    data = wwk_schools_df,
    icon = icon,
    popup = paste0(
      "<h2>School: ", wwk_schools_df$shortcut, "</h2>",
      "<b>Full name: </b>", wwk_schools_df$full_names, "<br>",
      "<b>Studying level: </b>", wwk_schools_df$levels, "<br>",
      "<b>Address: </b>", wwk_schools_df$addresses, "<br>",
      "<b>Number of teachers: </b>", wwk_schools_df$techaers_counts, "<br>",
       "<b>Creation year: </b>", wwk_schools_df$creations_years, "<br>"
    )
  ) %>%
  addLegend(
    colors = c("#9cc768", "#73c2e5", "#f8b66f"),
    labels = c("Primary school", "High school", "University"),
    title = "Study level",
    opacity = 1, 
    position = "bottomleft"
  ) %>%
  addControl(html = "<h1>Schools in Włołcawek</h1>", position = "topright")
## Assuming "long" and "lat" are longitude and latitude, respectively