2016-02-29 116 views
1

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的这些点。

回答

1

在你的问题中,你已经使用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) 

enter image description here

+0

@temor看看[单张R](https://rstudio.github.io/leaflet/),特别是[legents](https://rstudio.github.io/leaflet/legends.html)页面和[光栅图像]页面(https://rstudio.github.io/leaflet/raster.html)页面 – SymbolixAU

+0

@temor看着[错误消息](https://github.com/rstudio/leaflet/blob/master/R/colors.R),它表明你的范围内有一些“无限”的值。什么是'df $ t [!is.finite(df $ t)]'? – SymbolixAU

+0

我解决它,因为“”但我仍然有传奇的大小问题 – temor