R 地震热图的地理编码

R 地震热图的地理编码,r,ggplot2,plotly,heatmap,ggmap,R,Ggplot2,Plotly,Heatmap,Ggmap,我想画出加州吉尔罗伊地震加速度的热图。以下是我的数据;每个点的地理编码以十进制表示 lon lat Acc. -121.5897466 36.98443922 0.308722537 -121.5776472 36.98446622 0.343560598 -121.5657399 36.98449289 0.316238725 -121.5528172 36.98452208 0.289579654 -121.53976

我想画出加州吉尔罗伊地震加速度的热图。以下是我的数据;每个点的地理编码以十进制表示

    lon          lat            Acc.

-121.5897466    36.98443922 0.308722537
-121.5776472    36.98446622 0.343560598
-121.5657399    36.98449289 0.316238725
-121.5528172    36.98452208 0.289579654
-121.5397651    36.98455121 0.278277577
-121.6022388    36.9957913  0.321904187
-121.5897466    36.99578578 0.346187454
-121.57767    36.99578046   0.323865427
-121.5657514    36.99577518 0.296775313
-121.5528643    36.99576944 0.281054324
-121.5398582    36.99576372 0.270957516
-121.6264404    37.00268339 0.3504049
-121.614493     37.00268494 0.343426824
-121.6022388    37.00268646 0.34803746
-121.5897466    37.00268806 0.316975267
-121.5776805    37.00268967 0.300399358
-121.5657618    37.00269118 0.290519468
-121.5528861    37.0026927  0.27529488
-121.5399123    37.00269441 0.264715439
-121.6264404    37.01301756 0.352218819
-121.614493     37.01301354 0.342255779
-121.6022388    37.01300933 0.333444018
-121.5897466    37.01300512 0.315921346
-121.5777013    37.01300115 0.302762624
-121.5657723    37.01299709 0.291672835
-121.5529293    37.01299261 0.266912813
-121.614493     37.0204378  0.327864875
-121.6022388    37.0204297  0.321358226
-121.5897466    37.0204215  0.305797414
-121.5777125    37.02041366 0.293992548
-121.5657835    37.0204058  0.283948148
-121.614493    37.0299123   0.313950088
-121.6022388    37.02991694 0.303625182
-121.5897466    37.02992166 0.291511686
-121.5777299    37.02992617 0.282628812
-121.5657949    37.02993068 0.271427682
以下是我的代码:

    GilroyMap=   qmap(location = c(lon = -121.5837188, lat = 37.007846),zoom=12,color="color",legend="topleft",maptype = "terrain", darken=0.0, extent = "device")
data$C <- cut(data$Acc., breaks=10)

    Q=GilroyMap+stat_density2d(data = data, aes(x = lon, y = lat,fill = Acc. ), colour = NA, alpha = 0.5) +

        scale_fill_distiller(palette =1 , breaks = pretty_breaks(n = 10)) +
        labs(fill = "") +
        theme_nothing(legend = TRUE) +guides(fill = guide_legend(reverse = TRUE, override.aes = list(alpha = 1)))
gilloymap=qmap(位置=c(lon=-121.5837188,lat=37.007846),缩放=12,color=“color”,legend=“topleft”,maptype=“terrain”,darken=0.0,extent=“device”)

数据$C您可能需要使用
ggplot
ggmap
包:

library(ggmap)
library(ggplot2)


gilroy <- get_map(location = 'gilroy', zoom =12) 
ggmap(gilroy)


rbPal <- colorRampPalette(c('blue','red'))
mydata$Col <- rbPal(10)[as.numeric(cut(mydata$Acc.,breaks = 10))]

ggmap(gilroy, extent = "device") + geom_point(aes(x = lon, y = lat), colour = mydata$Col, 
      alpha = mydata$Acc., size = 6, shape = 15, data = mydata)
数据:

@42-:“但是,最好将所有数据实例更改为一个不同时也是R函数名的名称”(即
mydata


使用谷歌地图的解决方案如何(要使用它,您需要一个新的解决方案)

library(googleway)
地图键%
添加热图(数据=df,重量=Acc.,选项半径=0.02)

重复问题的可能重复:OR@rafa.pereira事实上,它不是,这就是为什么这是我的问题。在所有情况下,他们只考虑拉特和朗不是3个变量。因此,不能使用stat_density2d。stat_density2d绘制点的热图,而不是第三个变量。显然比我的答案要好得多+1编辑:但这对我不起作用。原因是什么?@Masoud-不确定;您是否有最新版本的
googelway
?还有一个有效的API密钥?@Masoud-我还调用了我的数据
df
我刚得到一个API并重新安装了
googleway
。Idk,对我来说也很奇怪。@SYMBOLXAU查看器仍然保持空白,没有任何错误。当我搜索时,这也是其他一些研究人员的问题。我重新安装了好几次软件包。
library(plotly)

g <- list(
  scope = 'usa',
  projection = list(type = 'albers usa'),
  showland = TRUE,
  landcolor = toRGB("gray95"),
  subunitcolor = toRGB("gray85"),
  countrycolor = toRGB("gray85"),
  countrywidth = 0.5,
  subunitwidth = 0.5)


p <- plot_geo(mydata, lat = ~lat, lon = ~lon) %>%
  add_markers( text = ~paste(lat, lon, Acc.,sep = "<br />"),
    color = ~Acc., symbol = I("square"), size = I(8), hoverinfo = "Acc."
  ) %>%
  colorbar(title = "Acc.") %>%
  layout(
    title = 'California Earthquake', geo = g)
read.table(text='lon          lat            Acc.

        -121.5897466    36.98443922 0.308722537
        -121.5776472    36.98446622 0.343560598
        -121.5657399    36.98449289 0.316238725
        -121.5528172    36.98452208 0.289579654
        -121.5397651    36.98455121 0.278277577
        -121.6022388    36.9957913  0.321904187
        -121.5897466    36.99578578 0.346187454
        -121.57767    36.99578046   0.323865427
        -121.5657514    36.99577518 0.296775313
        -121.5528643    36.99576944 0.281054324
        -121.5398582    36.99576372 0.270957516
        -121.6264404    37.00268339 0.3504049
        -121.614493     37.00268494 0.343426824
        -121.6022388    37.00268646 0.34803746
        -121.5897466    37.00268806 0.316975267
        -121.5776805    37.00268967 0.300399358
        -121.5657618    37.00269118 0.290519468
        -121.5528861    37.0026927  0.27529488
        -121.5399123    37.00269441 0.264715439
        -121.6264404    37.01301756 0.352218819
        -121.614493     37.01301354 0.342255779
        -121.6022388    37.01300933 0.333444018
        -121.5897466    37.01300512 0.315921346
        -121.5777013    37.01300115 0.302762624
        -121.5657723    37.01299709 0.291672835
        -121.5529293    37.01299261 0.266912813
        -121.614493     37.0204378  0.327864875
        -121.6022388    37.0204297  0.321358226
        -121.5897466    37.0204215  0.305797414
        -121.5777125    37.02041366 0.293992548
        -121.5657835    37.0204058  0.283948148
        -121.614493    37.0299123   0.313950088
        -121.6022388    37.02991694 0.303625182
        -121.5897466    37.02992166 0.291511686
        -121.5777299    37.02992617 0.282628812
        -121.5657949    37.02993068 0.271427682', header=TRUE, quote='"') -> 
    mydata  #named to have both code sections work and avoid a function name.
library(googleway)

mapKey <- 'your_api_key'

google_map(key = mapKey) %>%
    add_heatmap(data = df, weight = "Acc.", option_radius = 0.02)