地理编码的地震热图 [英] Heat Map of Earthquake by Geocodes

查看:89
本文介绍了地理编码的地震热图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制加州吉尔罗伊(Gilroy California)地震加速的热度.以下是我的数据;每个点的地理编码以十进制表示.

I would like to plot the heat of earthquake acceleration at Gilroy California. The following is my data; geocodes of each point is in decimal.

    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)))

它不起作用!

推荐答案

您可能要使用ggplotggmap软件包:

You may want to use ggplot and ggmap packages:

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)

这将给我们:

您也可以参考 R中的地图,使用plotly包进行此操作;

You can also do this using plotly package in reference to Maps in R;

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)

数据:

Data:

@ 42-:不过,将所有数据实例更改为既不是R函数名称又是更好的做法"(即mydata).

@42-: "It would, however, be better practice to change all instances of data to a name that was not also an R-function name" (i.e. mydata).

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.

这篇关于地理编码的地震热图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆