I am plotting data from two databases data_a
and data_b
with the following code.
library(leaflet)
library(readxl)
library(dplyr)
data_a <- structure(list(Nr = c(1, 2, 3, 4, 5, 6), Name = c("MD95-2006",
"IODP 302", "IODP 302", "IODP 302", "IODP 302", "IODP 302"),
Lat = c(57.083333, 87.89, 87.9036, 87.92118, 87.93333, 87.86658
), Long = c(-8.05, 137.65, 138.46065, 139.365501, 139.535,
136.17735), `18O` = c(0.69, NA, NA, NA, NA, NA), Info = c(NA_character_,
NA_character_, NA_character_, NA_character_, NA_character_,
NA_character_), Source = c("MD95-2006 planktic foraminifera ?13C and ?18O",
"https://www.ecord.org/expedition302/", "https://www.ecord.org/expedition302/",
"https://www.ecord.org/expedition302/", "https://www.ecord.org/expedition302/",
"https://www.ecord.org/expedition302/")), row.names = c(NA,
-6L), class = c("tbl_df", "tbl", "data.frame"))
data_b <- structure(list(Nr = c(1, 2, 3, 4, 5, 6), Name = c("Simstich",
"Schiebel", "Schiebel", "Stangeew", "Stangeew", "Stangeew"),
Lat = c(75.003333, 62.50275, 67.225033, 56.2747, 53.4347,
52.874), Long = c(-7.313333, -13.99235, 2.920317, -48.6992,
-50.0673, -51.5128), `18O` = c(NA, NA, NA, NA, NA, NA), Info = c("data for different depths",
NA, NA, NA, NA, NA), Source = c("https://doi.pangaea.de/10.1594/PANGAEA.82001?format=html#download",
"https://doi.pangaea.de/10.1594/PANGAEA.75647?format=html#download",
"https://doi.pangaea.de/10.1594/PANGAEA.75719", "https://doi.pangaea.de/10.1594/PANGAEA.706908",
"https://doi.pangaea.de/10.1594/PANGAEA.706908", "https://doi.pangaea.de/10.1594/PANGAEA.706908"
)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))
data <- bind_rows(list(data_a,data_b), .id="data_source")
icons <- awesomeIcons(
icon = 'ios-close',
iconColor = 'black',
library = 'ion',
markerColor = ifelse(data$data_source == 1, "green","red")
)
map <- leaflet(data) %>%
addTiles() %>%
addAwesomeMarkers(lng = ~Long, lat = ~Lat, icon = icons)
print(map)
The databases are structured as follows (already in the code).
You can see that they have a name. How can I make it so that I can see the names when I click on the icon? Unfortunately the website https://rstudio.github.io/leaflet/popups.html doesn't help me.
Hi the answer is quite simple!
only add popup = ~as.character(Name), label = ~as.character(Name)
to the row:
addAwesomeMarkers(lng = ~Long, lat = ~Lat, icon = icons, popup = ~as.character(Name), label = ~as.character(Name))
So the part should look like this:
map <- leaflet(data) %>%
addTiles() %>%
addAwesomeMarkers(lng = ~Long, lat = ~Lat, icon = icons, popup = ~as.character(Name), label = ~as.character(Name)) %>%