为什么我在球体上的内核密度估计不起作用?

时间:2019-03-13 15:49:01

标签: r leaflet kde

如上所述,我正在寻找密度/概率估计。参见here以了解与热图的区别,我检查了sum(kde$fhat)*diff(kde$x1[1:2])*diff(kde$x2[1:2]) = 1(可以在示例中运行,所有差异几乎相等)。
我希望在质量上与this Python example类似(需要向下滚动...),

enter image description here

但我明白了

enter image description here

增大网格大小可以改善这种情况,但会遇到局限性(请参见limit.memory()),带宽会稍微改变图片,但主要功能(较大区域的密度较低,较大区域的密度较小)仍未解决

怎么了?算法还是其他?因为我有更大的数据集,所以我在下面提供了一个包含1000点的数据集。 可复制的示例(或多或少来自here):

library("leaflet")
library("KernSmooth")
gc()
memory.limit(size=16000)

kde <- KernSmooth::bkde2D(dat[ , c("longitude", "latitude")],
              bandwidth=c(.0045, .0068),
              # bandwidth=c(.1, .1), # does not improve...
              gridsize = c(6000,6000))
CL <- contourLines(kde$x1 , kde$x2 , kde$fhat)

LEVS <- as.factor(sapply(CL, `[[`, "level"))
NLEV <- length(levels(LEVS))

pgons <- lapply(1:length(CL), function(i)
  sp::Polygons(list(sp::Polygon(cbind(CL[[i]]$x, CL[[i]]$y))), ID=i))
spgons = sp::SpatialPolygons(pgons)

leaflet(spgons) %>% addTiles() %>%
  addCircles(lng = dat$longitude, lat = dat$latitude,
             radius = .5, opacity = .9, col = "blue") %>%
  addPolygons(color = heat.colors(NLEV, NULL)[LEVS]) 

编辑:有用的链接,概述了available packages


数据

dat <- data.frame(latitude = c(
    47.086, 47.086, 46.979, 46.968, 47.053, 47.078, 47.044, 47.054, 
    46.935, 47.053, 46.832, 47.047, 47.065, 
     46.983, 47.082, 47.194, 46.962, 47.056, 46.977, 46.977, 47.171, 
     47.075, 47.056, 47.17, 47.043, 47.119, 47.166, 47.053, 46.771, 
     47.166, 47.064, 47.082, 47.144, 47.034, 47.065, 47.015, 47.032, 
     47.166, 47.085, 47.046, 47.209, 46.824, 47.058, 47.088, 47.083, 
     47.054, 47.05, 47.079, 47.046, 46.957, 47.131, 47.062, 46.962, 
     46.958, 47.218, 47.019, 47.042, 47.209, 47.049, 47.119, 47.041, 
     46.901, 46.736, 47.235, 47.05, 47.052, 47.047, 47.058, 47.135, 
     47.044, 47.166, 47.181, 46.88, 47.058, 47.048, 47.035, 47.058, 
     47.059, 46.881, 46.89, 47.065, 47.087, 47.077, 47.229, 47.082, 
     46.89, 47.054, 47.142, 47.048, 47.047, 47.062, 47.058, 47.026, 
     47.037, 47.038, 46.883, 47.059, 47.081, 47.051, 47.058, 47.249, 
     47.028, 47.217, 47.06, 47.05, 47.047, 47.038, 47.046, 46.962, 
     47.175, 47.057, 47.065, 46.821, 47.22, 46.945, 47.047, 47.151, 
     47.051, 47.21, 47.194, 47.171, 46.954, 46.958, 47.148, 46.818, 
     46.88, 46.872, 47.089, 47.037, 47.142, 47.096, 47.14, 46.969, 
     47.047, 47.085, 47.051, 47.13, 47.063, 47.06, 47.101, 47.05, 
     46.987, 47.082, 47.05, 46.89, 47.053, 47.056, 47.122, 47.041, 
     46.887, 47.055, 47.056, 47.042, 47.059, 46.987, 47.124, 47.062, 
     47.131, 47.059, 47.047, 47.055, 47.04, 47.075, 47.047, 46.959, 
     47.059, 47.049, 47.206, 46.9, 47.123, 47.015, 47.219, 47.166, 
     47.027, 47.021, 47.06, 47.153, 47.047, 47.057, 47.029, 47.042, 
     47.074, 47.214, 47.112, 47.086, 47.223, 47.018, 47.081, 47.173, 
     47.098, 46.961, 47.055, 46.973, 46.989, 47.018, 47.046, 46.944, 
     46.873, 47.056, 47.047, 47.223, 47.051, 47.073, 47.119, 46.962, 
     46.963, 47.057, 47.166, 47.047, 47.065, 47.167, 47.058, 46.87, 
     47.088, 47.051, 47.154, 47.035, 47.049, 46.714, 47.229, 47.09, 
     47.124, 47.059, 47.038, 47.038, 47.367, 46.975, 47.057, 46.833, 
     47.05, 47.04, 46.89, 47.139, 47.053, 47.051, 47.088, 47.051, 
     47.022, 46.878, 46.983, 47.075, 47.05, 47.194, 47.047, 47.188, 
     47.166, 47.006, 46.962, 47.062, 47.125, 46.881, 47.126, 46.957, 
     47.034, 47.073, 47.029, 47.075, 47.015, 47.042, 47.168, 47.096, 
     47.047, 47.073, 47.053, 47.047, 46.962, 46.89, 47.033, 47.033, 
     47.062, 46.707, 47.083, 47.051, 47.172, 47.059, 47.113, 47.032, 
     47.088, 47.062, 47.062, 46.89, 47.103, 47.043, 47.166, 47.058, 
     47.14, 47.073, 47.082, 47.153, 46.962, 47.059, 47.166, 47.059, 
     47.069, 47.227, 46.89, 47.232, 47.13, 47.021, 46.9, 47.085, 47.058, 
     47.09, 47.07, 46.906, 47.223, 46.894, 46.91, 47.08, 47.058, 47.242, 
     46.84, 46.89, 47.128, 47.182, 47.093, 47.05, 47.033, 47.107, 
     47.111, 47.166, 47.04, 47.166, 47.058, 46.89, 47.059, 47.058, 
     47.044, 47.059, 47.058, 46.956, 47.044, 47.152, 47.136, 47.166, 
     47.15, 47.052, 46.968, 47.232, 46.862, 47.034, 47.051, 47.089, 
     47.17, 47.084, 47.225, 47.167, 47.042, 47.078, 47.062, 47.086, 
     47.062, 47.061, 46.96, 47.046, 47.028, 47.058, 47.075, 47.062, 
     46.9, 47.125, 47.032, 47.044, 46.825, 47.048, 47.033, 47.049, 
     46.88, 47.157, 47.139, 47.202, 47.202, 47.059, 47.08, 47.039, 
     47.062, 47.166, 47.042, 47.231, 47.113, 47.056, 47.047, 47.052, 
     47.02, 47.156, 47.207, 46.893, 47.04, 47.065, 47.087, 47.063, 
     47.224, 47.02, 47.112, 47.062, 47.114, 47.058, 47.168, 47.048, 
     47.058, 47.055, 47.166, 46.994, 47.122, 47.081, 47.101, 47.047, 
     46.89, 46.978, 46.957, 47.062, 47.062, 47.038, 47.238, 47.166, 
     46.962, 47.038, 46.89, 47.059, 47.041, 47.047, 47.069, 46.975, 
     47.08, 47.086, 47.056, 47.055, 47.053, 47.074, 47.034, 47.051, 
     47.047, 46.875, 47.111, 47.119, 47.062, 47.058, 47.025, 47.062, 
     47.045, 47.117, 46.887, 46.962, 47.047, 47.107, 47.106, 47.047, 
     47.173, 47.184, 46.905, 47.166, 47.062, 47.153, 47.02, 47.161, 
     47.059, 47.055, 47.059, 47.209, 47.021, 47.058, 46.89, 47.044, 
     47.055, 47.13, 47.016, 47.034, 47.039, 47.188, 46.869, 47.165, 
     46.986, 47.049, 47.058, 47.039, 47.069, 47.036, 47.043, 47.053, 
     46.875, 47.103, 47.098, 47.201, 47.015, 47.047, 47.22, 47.092, 
     47.049, 47.209, 46.9, 47.171, 47.065, 46.956, 47.2, 47.058, 46.899, 
     47.032, 47.032, 47.049, 46.99, 46.944, 47.068, 47.05, 47.039, 
     47.11, 47.085, 46.891, 47.051, 47.225, 47.167, 46.897, 47.048, 
     47.05, 47.166, 47.166, 47.15, 47.222, 47.101, 46.976, 47.126, 
     47.061, 47.09, 47.373, 47.083, 47.039, 47.197, 46.962, 46.887, 
     46.89, 47.097, 47.142, 47.08, 47.062, 47.044, 47.058, 47.047, 
     47.212, 47.047, 47.161, 47.062, 47.045, 47.042, 46.986, 47.042, 
     47.137, 47.048, 46.951, 47.062, 46.954, 47.065, 47.054, 47.054, 
     47.044, 47.068, 46.877, 47.111, 47.173, 47.075, 47.166, 47.135, 
     46.957, 47.076, 46.966, 46.89, 46.985, 47.053, 47.2, 47.166, 
     47.065, 47.147, 47.055, 47.059, 47.088, 47.073, 47.118, 47.058, 
     47.058, 47.058, 47.131, 47.047, 47.033, 47.094, 47.052, 47.059, 
     46.904, 47.056, 47.042, 47.183, 46.884, 47.086, 47.086, 47.076, 
     46.89, 47.062, 46.729, 47.047, 47.152, 47.031, 47.082, 47.033, 
     47.174, 46.962, 47.042, 47.071, 46.869, 47.09, 47.142, 47.096, 
     47.071, 47.044, 47.142, 47.042, 46.884, 47.167, 46.977, 47.049, 
     47.059, 47.047, 46.89, 47.047, 47.051, 47.033, 47.044, 47.203, 
     46.823, 47.087, 47.059, 47.047, 47.177, 47.048, 46.99, 47.051, 
     47.061, 46.987, 47.073, 47.078, 47.055, 47.094, 46.893, 47.08, 
     47.171, 47.049, 47.064, 46.962, 47.054, 47.055, 46.872, 47.131, 
     46.872, 47.154, 47.029, 47.048, 46.872, 46.872, 46.872, 46.872, 
     46.872, 46.866, 47.053, 47.166, 47.042, 47.061, 47.244, 47.078, 
     47.124, 46.978, 47.059, 47.166, 47.074, 47.059, 47.038, 47.245, 
     47.245, 46.972, 46.887, 47.063, 47.057, 47.165, 47.02, 47.147, 
     47.017, 47.06, 47.06, 46.96, 47.05, 47.021, 46.962, 47.058, 46.987, 
     47.164, 47.142, 46.948, 46.967, 47.036, 47.047, 47.065, 47.066, 
     47.172, 47.049, 46.91, 47.084, 46.968, 46.956, 47.244, 47.115, 
     47.075, 47.066, 47.059, 47.027, 46.88, 47.085, 47.039, 47.033, 
     47.062, 47.166, 47.058, 47.17, 47.048, 47.113, 47.049, 46.825, 
     47.055, 47.069, 47.073, 47.03, 46.89, 47.058, 46.955, 47.037, 
     46.878, 47.171, 47.051, 46.957, 47.209, 47.032, 47.08, 47.151, 
     47.155, 47.081, 47.039, 47.168, 47.05, 47.082, 46.786, 46.837, 
     47.165, 46.869, 47.04, 46.907, 47.011, 47.02, 47.226, 47.047, 
     47.058, 47.161, 46.898, 46.787, 47.032, 46.889, 46.992, 47.016, 
     47.047, 47.053, 47.119, 47.061, 47.132, 47.046, 47.056, 47.166, 
     46.875, 47.21, 47.035, 47.053, 47.047, 47.131, 47.166, 47.042, 
     46.819, 47.07, 47.062, 47.08, 47.212, 47.049, 47.037, 47.08, 
     47.011, 46.89, 47.085, 47.092, 47.272, 47.035, 47.232, 47.035, 
     47.171, 47.067, 46.951, 47.086, 47.138, 47.165, 47.047, 46.882, 
     46.994, 46.89, 47.053, 47.166, 47.095, 47.051, 47.166, 47.047, 
     47.021, 47.236, 47.043, 47.187, 47.166, 47.062, 47.026, 46.862, 
     47.044, 47.044, 47.085, 47.053, 47.062, 46.89, 46.962, 47.166, 
     47.047, 47.059, 46.962, 47.074, 47.106, 47.051, 47.167, 46.966, 
     47.056, 47.062, 47.062, 47.062, 46.9, 47.047, 47.053, 47.077, 
     47.055, 47.037, 47.066, 47.042, 47.156, 47.037, 47.078, 47.13, 
     47.092, 46.984, 46.862, 47.093, 47.209, 47.204, 47.122, 47.051, 
     47.038, 47.142, 47.135, 47.129, 47.152, 47.083, 47.044, 47.053, 
     47.177, 47.062, 47.047, 46.944, 47.055, 47.199, 47.079, 47.036, 
     47.044, 47.051, 46.962, 47.079, 47.021, 46.962, 46.962, 46.897, 
     47.122, 47.165, 47.058, 47.055, 47.084, 47.069, 47.058, 46.91, 
     47.058, 47.034, 47.172, 47.065, 47.032, 47.033, 47.049, 46.704, 
     47.153, 47.147, 47.057, 47.035, 46.884, 47.051, 47.059, 47.151, 
     47.032, 47.087, 46.962, 47.014, 46.962, 47.036, 47.058, 46.963, 
     47.075, 46.865, 47.171, 47.064, 46.828, 47.047, 47.076, 47.059, 
     47.042, 47.06, 47.029, 47.166, 47.101, 47.105, 47.074, 46.962, 
     47.161, 47.058, 47.142, 46.979, 46.926, 47.05, 47.141, 47.058, 
     47.058, 47.075, 47.062, 47.176, 47.065, 47.059, 46.979, 47.095, 
     46.962, 47.237, 47.05, 47.012, 47.023, 47.033, 47.062, 47.122, 
     47.168, 47.063, 47.061, 46.859, 46.889, 47.029, 47.065, 47.039, 
     46.962, 47.032, 47.044, 46.866, 46.89, 47.209, 47.18, 46.857, 
     47.031, 47.021, 46.991, 47.048, 46.962, 46.884, 46.895, 46.884, 
     47.165, 46.957, 46.962, 47.047, 47.08, 47.08, 46.952, 47.115, 
     47.059, 46.874, 47.05, 47.211, 47.214, 47.183, 46.965, 47.075, 
     47.051, 46.861, 47.209, 47.076, 47.041, 46.881, 47.024), 
  longitude = c(8.262, 8.435, 8.337, 8.364, 8.301, 8.361, 8.297, 8.337, 8.394, 8.283, 
                8.289, 8.307, 8.078, 8.41, 8.344, 8.521, 8.356, 8.312, 8.306, 
                8.306, 8.104, 8.438, 8.098, 8.29, 8.373, 8.342, 8.118, 8.3, 8.671, 
                8.118, 8.278, 8.13, 8.014, 8.332, 8.318, 8.478, 8.284, 8.118, 
                8.351, 8.302, 8.192, 8.65, 8.294, 8.319, 8.444, 8.069, 8.311, 
                8.299, 8.302, 8.371, 8.192, 8.299, 8.356, 8.369, 7.95, 8.311, 
                8.185, 8.187, 8.339, 7.988, 8.324, 8.281, 8.628, 8.078, 8.314, 
                8.294, 8.314, 8.326, 8.192, 8.297, 8.118, 8.283, 8.016, 8.294, 
                8.376, 8.244, 8.294, 8.348, 8.645, 8.244, 8.078, 8.34, 8.277, 
                7.844, 8.344, 8.244, 8.385, 8.132, 8.309, 8.314, 8.299, 8.294, 
                8.307, 8.155, 8.288, 8.646, 8.294, 8.44, 8.311, 8.284, 7.97, 
                8.305, 8.267, 8.285, 8.309, 8.298, 8.261, 8.38, 8.356, 8.128, 
                8.289, 8.073, 8.653, 8.158, 7.424, 8.314, 8.318, 8.339, 8.097, 
                8.515, 8.104, 8.047, 8.39, 8.223, 8.411, 8.244, 8.376, 8.278, 
                8.281, 7.973, 8.279, 7.924, 8.352, 8.314, 8.351, 8.262, 8.319, 
                8.319, 8.275, 8.28, 8.275, 8.311, 8.304, 8.311, 8.244, 8.259, 
                8.32, 7.99, 8.298, 8.231, 8.356, 8.292, 8.318, 8.279, 8.311, 
                8.349, 8.299, 8.315, 8.294, 8.302, 8.332, 8.323, 8.279, 8.314, 
                8.36, 8.279, 8.299, 8.194, 8.269, 8.397, 8.31, 8.262, 8.118, 
                8.279, 8.316, 8.276, 8.163, 8.314, 8.324, 8.421, 8.311, 8.36, 
                7.989, 8.096, 8.397, 8.113, 8.316, 8.441, 7.989, 8.267, 8.363, 
                8.282, 8.338, 8.313, 8.311, 8.309, 8.277, 8.271, 8.313, 8.314, 
                8.253, 8.311, 8.274, 7.991, 8.356, 8.37, 8.331, 8.118, 8.314, 
                8.078, 8.289, 8.294, 8.655, 8.272, 8.306, 8.324, 8.292, 8.299, 
                8.612, 8.262, 8.267, 8.352, 8.285, 8.425, 8.312, 8.499, 8.427, 
                8.302, 8.184, 8.256, 8.309, 8.244, 8.194, 8.267, 8.311, 7.959, 
                8.308, 8.312, 8.713, 8.403, 8.29, 8.301, 8.515, 8.314, 8.017, 
                8.118, 8.305, 8.356, 8.28, 8.386, 8.253, 8.199, 8.371, 8.423, 
                8.288, 8.335, 8.329, 8.48, 8.326, 8.106, 8.454, 8.264, 8.275, 
                8.35, 8.314, 8.356, 8.244, 8.286, 8.284, 8.299, 8.597, 8.344, 
                8.337, 8.283, 8.294, 8.393, 8.279, 8.354, 8.299, 8.299, 8.244, 
                8.342, 8.362, 8.118, 8.294, 8.192, 8.26, 8.312, 8.168, 8.356, 
                8.29, 8.118, 8.428, 8.316, 8.078, 8.244, 8.08, 8.138, 8.316, 
                8.275, 8.351, 8.294, 8.267, 8.325, 7.93, 8.11, 8.249, 8.622, 
                8.44, 8.326, 8.226, 8.175, 8.244, 8.236, 7.982, 7.97, 8.307, 
                8.272, 8.194, 8.195, 8.118, 8.319, 8.118, 8.294, 8.244, 8.279, 
                8.294, 8.297, 8.279, 8.294, 8.382, 8.297, 8.089, 8.317, 8.118, 
                8.172, 8.284, 8.364, 8.078, 8.644, 8.27, 8.309, 8.278, 8.115, 
                8.041, 8.081, 8.295, 8.366, 8.333, 8.299, 8.294, 8.315, 8.388, 
                8.528, 8.305, 8.294, 8.294, 8.286, 8.299, 8.274, 8.446, 8.279, 
                8.297, 8.651, 8.313, 8.329, 8.313, 8.646, 8.116, 7.919, 8.234, 
                8.234, 8.294, 8.345, 8.303, 8.312, 8.118, 8.187, 8.237, 8.096, 
                7.949, 8.302, 8.3, 8.315, 8.316, 8.189, 8.245, 8.307, 8.078, 
                8.289, 8.073, 8.26, 8.311, 8.454, 8.299, 8.277, 8.294, 8.098, 
                8.309, 8.308, 8.321, 8.118, 8.308, 8.355, 8.348, 8.253, 8.314, 
                8.249, 8.341, 8.369, 8.299, 8.299, 8.181, 8.139, 8.118, 8.356, 
                8.327, 8.249, 8.294, 8.298, 8.314, 8.317, 8.343, 8.345, 8.039, 
                8.35, 8.299, 8.307, 8.366, 8.266, 8.296, 8.315, 8.641, 8.195, 
                7.988, 8.299, 8.326, 8.307, 8.315, 8.303, 7.984, 8.231, 8.356, 
                8.314, 8.451, 8.355, 8.068, 8.1, 8.027, 8.274, 8.118, 8.074, 
                8.325, 8.278, 8.104, 8.301, 8.318, 8.294, 8.196, 8.308, 8.315, 
                8.244, 8.306, 8.318, 8.319, 8.301, 8.143, 8.179, 7.975, 8.643, 
                8.114, 8.312, 8.306, 8.302, 8.289, 8.36, 8.321, 8.304, 8.302, 
                8.664, 8.267, 8.465, 8.247, 8.309, 8.305, 8.249, 8.395, 8.268, 
                8.178, 8.269, 8.285, 8.078, 8.273, 8.314, 8.294, 8.262, 8.278, 
                8.285, 8.312, 8.424, 8.277, 8.366, 8.309, 8.325, 8.361, 8.437, 
                8.239, 8.308, 8.147, 8.291, 8.391, 8.301, 8.312, 8.118, 8.118, 
                8.229, 8.264, 8.269, 8.344, 8.402, 8.353, 8.105, 8.559, 8.337, 
                8.32, 8.229, 8.356, 8.231, 8.244, 8.276, 8.132, 8.287, 8.299, 
                8.297, 8.294, 8.264, 8.016, 8.314, 8.296, 8.299, 8.28, 8.301, 
                8.412, 8.301, 8.315, 8.364, 8.383, 8.299, 8.014, 8.078, 8.346, 
                8.346, 8.314, 8.317, 8.643, 8.321, 8.1, 8.27, 8.118, 8.131, 8.336, 
                8.286, 8.47, 8.244, 8.312, 8.345, 8.314, 8.118, 8.078, 8.016, 
                8.311, 8.294, 8.292, 8.295, 7.987, 8.294, 8.294, 8.294, 8.315, 
                8.314, 8.327, 8.344, 8.294, 8.294, 8.277, 8.349, 8.14, 8.006, 
                8.637, 8.346, 8.03, 8.267, 8.244, 8.299, 8.546, 8.289, 8.167, 
                8.278, 7.954, 8.286, 8.103, 8.356, 8.301, 8.288, 8.652, 8.267, 
                8.132, 8.369, 8.282, 8.297, 8.132, 8.315, 8.637, 8.291, 8.417, 
                8.262, 8.279, 8.314, 8.244, 8.314, 8.311, 8.293, 8.3, 8.432, 
                8.404, 8.289, 8.294, 8.298, 8.101, 8.267, 8.306, 8.311, 8.306, 
                8.311, 8.434, 8.343, 8.324, 8.372, 8.245, 8.301, 8.113, 8.262, 
                8.306, 8.356, 8.311, 8.304, 8.376, 8.192, 8.376, 8.03, 8.421, 
                8.348, 8.376, 8.376, 8.376, 8.376, 8.376, 8.65, 8.338, 8.118, 
                8.324, 8.281, 8.137, 8.343, 8.163, 8.415, 8.294, 8.118, 8.329, 
                8.294, 8.321, 8.223, 8.223, 8.444, 8.231, 8.303, 8.301, 8.29, 
                8.307, 8.234, 8.31, 8.068, 8.347, 8.362, 8.307, 8.316, 8.356, 
                8.294, 8.415, 8.298, 8.132, 8.05, 8.422, 8.329, 8.314, 8.078, 
                8.017, 8.096, 8.309, 7.936, 8.31, 8.364, 8.365, 7.966, 7.993, 
                8.283, 8.077, 8.294, 8.302, 8.244, 8.434, 8.313, 8.286, 8.286, 
                8.118, 8.294, 8.105, 8.376, 8.393, 8.313, 8.391, 8.346, 8.316, 
                8.275, 8.25, 8.244, 8.326, 8.362, 8.311, 8.647, 8.106, 8.308, 
                8.37, 8.196, 8.284, 8.084, 8.167, 8.214, 8.277, 8.185, 8.142, 
                8.264, 8.444, 8.162, 8.634, 8.291, 8.644, 8.182, 8.297, 8.339, 
                8.315, 8.255, 8.314, 8.326, 8.291, 8.248, 8.159, 8.284, 8.206, 
                8.305, 8.661, 8.302, 8.069, 7.992, 8.31, 8.195, 8.191, 8.344, 
                8.118, 8.664, 7.979, 8.281, 8.286, 8.302, 8.195, 8.118, 8.326, 
                8.387, 8.325, 8.299, 8.281, 8.093, 8.303, 8.272, 8.281, 8.293, 
                8.249, 8.349, 8.342, 8.235, 8.259, 8.08, 8.259, 8.293, 8.314, 
                8.62, 8.442, 8.083, 8.297, 8.264, 8.247, 8.308, 8.244, 8.3, 8.118, 
                8.278, 8.298, 8.118, 8.29, 8.316, 8.077, 8.313, 8.237, 8.118, 
                8.299, 8.307, 8.644, 8.35, 8.297, 8.351, 8.284, 8.299, 8.244, 
                8.356, 8.118, 8.298, 8.294, 8.356, 8.335, 8.374, 8.27, 8.118, 
                8.382, 8.301, 8.299, 8.299, 8.299, 8.626, 8.298, 8.285, 8.277, 
                8.324, 8.282, 8.314, 8.301, 8.328, 8.183, 8.264, 8.311, 8.35, 
                8.413, 8.644, 8.275, 8.093, 8.039, 7.99, 8.347, 8.306, 8.132, 
                7.924, 8.319, 8.115, 8.125, 8.297, 8.277, 8.209, 8.299, 8.314, 
                8.277, 8.308, 7.967, 8.124, 8.431, 8.314, 8.311, 8.356, 8.27, 
                8.316, 8.356, 8.356, 8.26, 7.987, 8.297, 8.294, 8.316, 8.345, 
                8.281, 8.088, 8.622, 8.294, 8.27, 8.096, 8.078, 8.284, 8.449, 
                8.301, 8.6, 8.325, 8.108, 8.341, 8.328, 8.637, 8.298, 8.294, 
                8.227, 8.442, 8.037, 8.356, 8.305, 8.356, 8.333, 8.326, 8.363, 
                8.283, 8.649, 8.102, 8.316, 8.188, 8.314, 8.267, 8.279, 8.318, 
                8.347, 8.056, 8.118, 8.203, 8.269, 8.338, 8.356, 8.265, 8.326, 
                8.132, 8.341, 8.26, 8.339, 8.327, 8.294, 8.294, 8.438, 8.315, 
                8.136, 8.078, 8.294, 8.419, 8.27, 8.016, 8.073, 8.34, 8.486, 
                8.307, 8.275, 8.315, 7.99, 7.996, 8.303, 8.275, 8.655, 8.249, 
                8.421, 8.078, 8.314, 8.356, 8.289, 8.297, 8.237, 8.244, 8.178, 
                8.112, 8.646, 8.399, 8.316, 8.307, 8.301, 8.356, 8.637, 8.621, 
                8.637, 8.297, 8.372, 8.356, 8.314, 8.441, 8.345, 8.016, 8.39, 
                8.279, 8.674, 8.312, 7.99, 7.991, 8.023, 8.475, 8.283, 8.308, 
                8.658, 8.096, 8.439, 8.306, 8.645, 8.454),
  stringsAsFactors = FALSE)

1 个答案:

答案 0 :(得分:2)

您可能想看看leaflet.extras。它具有内置的热图机会。

library(magrittr)
library(leaflet)
library(leaflet.extras)
leaflet(dat) %>% addTiles() %>%
  addHeatmap(lng = ~longitude, lat = ~latitude, radius = 10, minOpacity = .5) %>%
  addCircles(lng = ~longitude, lat = ~latitude)

enter image description here

为了进一步使其适合您的需求,您可能需要使用radiusblurminOpacitymax属性。要调整调色板,可以使用gradient

例如:

leaflet(dat) %>% addTiles() %>%
  addHeatmap(lng = ~longitude, lat = ~latitude, blur = 20, radius = 10, minOpacity = .5, gradient = RColorBrewer::brewer.pal(7, "Reds")) %>%
  addCircles(lng = ~longitude, lat = ~latitude)

enter image description here