Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Leaflet map displays wrong location based on lat,long data

There are my data with Poland coordinates

omited5<-structure(list(scientificName = c("Turdus merula Linnaeus, 1758", 
"Passer domesticus (Linnaeus, 1758)", "Cantharellus cinereus (Pers.) Fr.", 
"Flammulina fennae Bas", "Mycena crocata (Schrad.) P.Kumm.", 
"Lepista luscina (Fr.) Singer", "Mycena permixta (Britzelm.) Sacc.", 
"Rhodophyllus byssisedus (Pers.) Quel.", "Rhodophyllus porphyrophaeus (Fr.) J.E.Lange", 
"Panaeolus rickenii Hora", "Lactarius badiosanguineus Kuhner & Romagn.", 
"Lactarius flexuosus Gray", "Lactarius trivialis (Fr.) Fr.", 
"Ramaria apiculata (Fr.) Donk", "Pleurotus vetlinianus Domanski", 
"Ramaria rasilispora var. scatesiana Marr & D.E.Stuntz", "Stropharia thrausta (Kalchbr.) Sacc.", 
"Marasmius tremulae Velen.", "Pholiota alnicola (Fr.) Singer", 
"incertae sedis", "Agrocybe firma (Peck) Singer", "Rhodocybe caelata (Fr.) Maire", 
"Melanoleuca subbrevipes Metrod", "Russula pseudointegra Arnould & Goris", 
"Porpoloma pes-caprae (Fr.) Singer", "Camarophyllus schulzeri (Bres.) Ricken", 
"Pluteus leoninus (Schaeff.) P.Kumm.", "Pholiota adiposa (Batsch) P.Kumm.", 
"Pleurocybella lignatilis (Pers.) Singer", "Pholiota aurivella (Batsch) P.Kumm.", 
"Lentinus adhaerens (Alb. & Schwein.) Fr.", "Hygrocybe splendidissima (P.D.Orton) M.M.Moser", 
"Cystoderma cinnabarinum (Alb. & Schwein.) Fayod", "Dermoloma atrocinereum (Pers.) Herink", 
"Hygrocybe calyptriformis (Berk.) Fayod", "Hygrocybe intermedia (Pass.) Fayod", 
"Stropharia squamosa (Pers.) Quel.", "Hygrocybe quieta (Kuhner) Singer", 
"Psathyrella cernua (Vahl) G.Hirsch", "BOLD:ADC3719", "BOLD:AAE7687", 
"BOLD:AAJ1655", "BOLD:ADW5701", "BOLD:AAN9573", "Culicoides obsoletus (Meigen, 1818)", 
"BOLD:AAK9478", "Perccottus glenii Dybowski, 1877", "Culicoides obsoletus (Meigen, 1818)", 
"BOLD:AAE6136", "Culicoides scotti Kieffer, 1911"), verbatimScientificName = c("Turdus merula Linnaeus, 1758", 
"Passer domesticus (Linnaeus, 1758)", "Cantharellus cinereus", 
"Flammulina fennae", "Mycena crocata", "Lepista luscina", "Mycena permixta", 
"Rhodophyllus byssisedus", "Rhodophyllus porphyrophaeus", "Panaeolus rickenii", 
"Lactarius badiosanguineus", "Lactarius flexuosus", "Lactarius trivialis", 
"Ramaria apiculata", "Pleurotus vetlinianus", "Ramaria rasilispora scatesiana", 
"Stropharia thrausta", "Marasmius tremulae", "Pholiota alnicola", 
"Dermoloma pseudoconeifolium", "Agrocybe firma", "Rhodocybe caelata", 
"Melanoleuca subbrevipes", "Russula pseudointegra", "Porpoloma pes-caprae", 
"Camarophyllus schulzeri", "Pluteus leoninus", "Pholiota adiposa cerifera", 
"Pleurocybella lignatilis", "Pholiota aurivella", "Lentinus adhaerens", 
"Hygrocybe splendidissima", "Cystoderma cinnabarinum", "Dermoloma atrocinereum", 
"Hygrocybe calyptriformis", "Hygrocybe intermedia", "Stropharia squamosa", 
"Hygrocybe quieta", "Psathyrella cernua", "BOLD:ADC3719", "BOLD:AAE7687", 
"BOLD:AAJ1655", "BOLD:ADW5701", "BOLD:AAN9573", "Culicoides obsoletus", 
"BOLD:AAK9478", "Perccottus glenii", "Culicoides obsoletus", 
"BOLD:AAE6136", "Culicoides scoticus"), year = c(2015, 2015, 
1892, 2006, 1967, 1967, 1967, 1967, 1967, 1967, 1966, 1966, 1966, 
1966, 2014, 1970, 1967, 1967, 1967, 1970, 1967, 1967, 1967, 1967, 
1967, 1967, 1967, 1966, 1967, 1967, 1967, 1967, 1966, 1967, 1966, 
1967, 1966, 1967, 1967, 2019, 1973, 2010, 2012, 2008, 2016, 2013, 
2018, 2016, 2010, 2016), decimalLatitude = c(52.204429, 51.387818, 
52.176667, 50.066111, 49.179167, 49.419444, 52.3, 52.3, 49.419444, 
49.179167, 53.85, 52, 53.902778, 50.894444, 49.516667, 54.122222, 
49.179167, 52.7, 52.7, 49.419444, 52, 49.9, 49.419444, 52.7, 
49.983333, 49.9, 49.179167, 52.7, 52.7, 52, 49.419444, 49.473611, 
53.85, 49.419444, 49.473611, 49.419444, 52.7, 49.473611, 52.7, 
54.112, 51.633, 52.1704, 51.85, 53.03, 49.75, 52.69, 52.3356, 
49.751, 54.1716, 49.75), decimalLongitude = c(21.189275, 19.62673, 
19.088056, 19.502778, 22.434722, 20.380556, 20.566667, 20.566667, 
20.380556, 22.434722, 22.983333, 20, 16.044444, 20.904167, 21.516667, 
17.981111, 22.434722, 23.833333, 23.833333, 20.380556, 20, 20.9, 
20.380556, 23.833333, 22.166667, 20.9, 22.434722, 23.833333, 
23.833333, 20, 20.380556, 22.661111, 22.983333, 20.380556, 22.661111, 
20.380556, 23.833333, 22.661111, 23.833333, 23.043, 14.833, 22.2784, 
17.16, 14.28, 22.79, 23.891, 20.9142, 22.86, 23.3642, 22.79)), row.names = c(NA, 
-50L), class = c("tbl_df", "tbl", "data.frame"))

the issue is that as you can see the map is showing me aplace in Arabic penisula instead of Poland.

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

library(leaflet)
leaflet(data = omited5) %>% addTiles() %>%
          addMarkers(~decimalLatitude, ~decimalLongitude, popup = ~as.character(paste("Name:",scientificName,"-","Year:",year,sep="\n")))%>%
          setView(lng = 19.0, lat = 52.0, zoom = 6)  # Center over Poland

>Solution :

It seems that you mixed up the order of latitude and longitude when passing along to addMarkers. See example Customizing Marker Icons:

# ...

leaflet(data = quakes[1:4,]) %>% addTiles() %>%
  addMarkers(~long, ~lat, icon = greenLeafIcon)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading