To visualize Kale accession data using Leaflet in RMarkdown, First I
need to convert the DMS (degrees-minutes-seconds) coordinates to decimal
degrees. Here’s a complete RMarkdown example that reads your data,
transforms coordinates, and plots them on an interactive map using the
leaflet
package.
# Raw data
accessions <- data.frame(
Accession = c("Bc001","Bc002","Bc003","Bc004","Bc005","Bc006","Bc007","Bc008","Bc009","Bc010","Bc011","Bc012","Bc013"),
Latitude = c("06˚08'00\"", "08˚20'00\"", "08˚63'10\"", "06˚09'00\"", "08˚10'00\"", "08˚22'47\"", "06˚15'12°", "06˚09'00\"", "08˚00'58\"", "06˚17'14\"", "06˚18'00\"", "06˚17'00\"", "06˚10'71\""),
Longitude = c("37˚35'00\"", "37˚36'00\"", "38˚10'14\"", "37˚35'00\"", "37˚18'00\"", "37˚38'21\"", "38˚14'00°", "37˚35'00\"", "38˚31'41\"", "38˚13'02\"", "38˚01'00\"", "38˚14'00\"", "37˚44'19\""),
Altitude = c(1930,2000,2243,2200,2150,1470,2230,2200,1880,2000,1600,1820,1470),
Woreda = c("Sodo","Abeshge","Esha","Cheha","Sodo","Abeshge","Gedeb","Cheha","Meskan","Wenago","Gedeb","Wenago","Cheha"),
Zone = c("Gurage","Gurage","Gurage","Gurage","Gurage","Gurage","Gedeo","Gurage","Gurage","Gedeo","Gedeo","Gedeo","Gurage"),
Region = c("Central Ethiopia","Central Ethiopia","Central Ethiopia","Central Ethiopia","Central Ethiopia","Central Ethiopia","South Ethiopia","Central Ethiopia","Central Ethiopia","South Ethiopia","South Ethiopia","South Ethiopia","Central Ethiopia"),
stringsAsFactors = FALSE
)
# Helper to convert DMS to decimal
dms_to_dec <- function(dms) {
parts <- str_match(dms, "(\\d+)˚(\\d+)'(\\d+)")
deg <- as.numeric(parts[,2])
min <- as.numeric(parts[,3])
sec <- as.numeric(parts[,4])
return(deg + min/60 + sec/3600)
}
accessions$Latitude_dd <- sapply(accessions$Latitude, dms_to_dec)
accessions$Longitude_dd <- sapply(accessions$Longitude, dms_to_dec)
leaflet(accessions) %>%
addTiles() %>%
addCircleMarkers(
~Longitude_dd, ~Latitude_dd,
label = ~paste(Accession, Woreda, Zone, Region, sep = " | "),
radius = 5,
color = "blue",
fillOpacity = 0.7
) %>%
addProviderTiles("Esri.WorldImagery")