如何在地图上添加根据变量值着色的点?

时间:2018-08-30 12:52:09

标签: r geolocation

使用这些说明:win.graph()

awk '
    /^>/ {
        getline next_line
        print $0 "_" length(next_line)
        print next_line
    }
' test1.faa

不是出于错误,而是没有做到。

1 个答案:

答案 0 :(得分:0)

欢迎来到SO。通常,最好包括您可能已加载的软件包以及问题本身的更多说明。

这是使用plotly的方法。我正在使用ggplot2::map_data()生成一些示例数据(较大的数据集)并显示其工作方式:

library(ggplot2)
library(plotly)

dat <- map_data(map = 'county')

# map_data() is a large dataset, I'm limiting the map to 50 observations
# the coords$value field is the variable that determines the color of the mapped point
coords <- dat[sample(sample(x = 1:nrow(dat), size = 50, replace = T)), ]
coords$value <- rnorm(n = nrow(coords), mean = 10, sd = 3)

# some code to let plotly know we're plotting a map (projection etc.) 
g <- list(
  scope = 'usa',
  projection = list(type = 'Mercator'),
  showland = TRUE,
  landcolor = toRGB("gray85"),
  subunitwidth = 1,
  countrywidth = 1,
  subunitcolor = toRGB("white"),
  countrycolor = toRGB("white")
)


plt <- plot_geo(locationmode = 'USA-states', sizes = c(1, 250), data = coords) %>%
  add_markers(x = ~long, y = ~lat, color = ~value) %>%
  layout(title = 'County Map', 
         geo = g)

输出 enter image description here