根据条件生成随机虚假地理数据

时间:2015-07-10 13:10:57

标签: r leaflet

我正在考虑用一些假随机数据生成假地图的最佳方法是什么,但是遵循一些条件。例如,我希望在“Deleng”河以东有12个点,在西边有12个点。我希望颜色的平均值比西方更高。除此之外,我希望这些点是随机的

这是我现在的代码:

set.seed(7102015)

gen.schools <- function(n.schools){
  School.long <- rnorm(n = n.schools, mean = 21.7672, sd = 0.025)
  School.lat <- rnorm(n = n.schools, mean = 58.8471, sd = 0.025)
  School.VAM <- rnorm(n = n.schools, mean = 0, sd = 1)
  Schools <- data.frame(School.lat, School.long, School.VAM)
  return(Schools)
}

district.map <- gen.schools(n.schools = 20)

library(leaflet)
# Create a continuous palette function
pal <- colorNumeric(
  palette = "RdYlBu",
  domain = district.map$School.VAM
)

leaflet() %>% addTiles("http://opengeofiction.net/osm_tiles/{z}/{x}/{y}.png") %>%
  setView(lng = 21.7672, lat = 58.8471, 13) %>%
  addCircleMarkers(data = district.map, lat = ~School.lat, lng =~School.long, 
                   fillColor = ~pal(School.VAM),
                   stroke = FALSE, fillOpacity = 1) %>% 
  addLegend(position = "topright",
            pal = pal, values = district.map$School.VAM,
            title = "Performance Index",
            opacity = 1
  )

如果使用河流作为条件是不可能的,我可以在这个假地图上叠加一个精细的长网格,这样我就可以手工挑选这些点吗?

谢谢!

0 个答案:

没有答案