[英]How to show the legend (scale colour) for points on a map?
版本R 3.2.3
library(OpenStreetMap)
map <- openmap(c(lat= 48, lon= 3), c(lat= 40, lon= 0))
map <- openproj(map)
plot(map)
lon=c(1, 03, 04, 08, -1)
lat=c(40, 41, 41, 42, 41)
x=c(1, 3, 0.1, 2, 1) #I give here example of only 5 values but my real values are many and vary. So the values here are not discrete but continuous!
points(lon,lat,pch=19,col=x) #not sure here how
我想在地圖上用從藍色到紅色的顏色范圍繪制x的這些點,最重要的是在地圖旁邊顯示比例尺顏色(圖例)。
在您的問題中,您使用過OpenStreetMap
(我無法運行); 您不利於使用leaflet
嗎?
如果沒有,你可以做
library(leaflet)
df <- data.frame(lon=c(1, 03, 04, 08, -1),
lat=c(40, 41, 41, 42, 41),
x=c(1, 3, 0.1, 2, 1))
pal <- colorNumeric(
palette = c("#ff0000","#0000ff"),
domain = df$x
)
leaflet() %>%
setView(lng = 3, lat = 48, zoom = 4) %>%
addProviderTiles("Esri.WorldGrayCanvas") %>% ## pick any map layer you want
addCircleMarkers(data = df, lng = ~lon, lat = ~lat, stroke=FALSE, color=~pal(x), fillOpacity = 0.6) %>%
addLegend(position = c("bottomleft"), pal = pal, values = df$x)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.