R-美国各县的地图

时间:2019-10-21 11:15:51

标签: r plotly r-plotly

我对R相当陌生,但是已经设法按美国州立大学绘制了一些数据。我现在想将其降至县级级别,但目前正在努力转换我的代码:

  output$County_Map <- renderPlotly({

    ct_Map_Data <- County_data()
    ct_Map_Data <- ct_Map_Data[,c("CODE", "COUNTY", "VALUE", "COUNTY.LIMIT")]
    ct_Map_Data$COUNTY.LIMIT <- as.numeric(gsub("," ,"", ct_Map_Data$COUNTY.LIMIT))
    ct_Map_Data$VALUE[is.na(ct_Map_Data$VALUE)] <- 0
    ct_Map_Data$COUNTY.LIMIT[is.na(ct_Map_Data$COUNTY.LIMIT)] <- 0

    # give state boundaries a white border
    l <- list(color = toRGB("white"), width = 2)
    # specify some map projection/options
    g <- list(
      scope = 'usa',
      projection = list(type = 'albers usa'),
      showlakes = TRUE,
      lakecolor = toRGB('white')
    )

    p <- plot_geo(ct_Map_Data, locationmode = 'USA-counties') %>%
      add_trace(
        z = ~VALUES, text = ~COUNTY, locations = ~CODE,
        color = ~VALUES, colors = 'Blues'
      ) %>%
      colorbar(title = "VALUE (USD)")
    #%>%
      #layout(
       # title = paste(input$acc_x, ' - Value by County'),
        geo = g
#      )
    p

  })

代码以某种格式开始,但是随后我尝试绘制数据。我从状态代码映射更改的唯一一件事是将locationmode = 'USA-states'更改为locationmode = 'USA-counties'

我不确定如何找到答案,但是我想我的第一个问题是,是否可以从州地图上绘制县地图?

谢谢。

0 个答案:

没有答案