ggplot2-图和图例中的编号点

时间:2019-07-14 04:47:51

标签: r ggplot2

我正在尝试使用ggplot创建地图,在地图上使用地图上的点和数字来指示站点,并且该编号方案保留在图例中。因此,我希望第一个站点的中心标记为数字1,以此类推。现在是我的代码:

library(tidyverse)

# download site data

dod <- read_csv('https://raw.githubusercontent.com/jaymwin/fcpp_GIS/master/data/DoD_sites_latlong.csv') %>%
  filter(site != 'Fort Wainwright') %>%
  mutate(
    num = row_number() # my way of numbering the sites
  )
dod

# download state outlines

states <- map_data('state')

# plot them

ggplot() +
  geom_polygon(data = states, aes(long, lat, group = group), fill = 'grey95', color = 'darkgrey') +
  geom_point(data = dod, aes(x = lon, y = lat, color = site), size = 4) +
  geom_text(data = dod, aes(label = num, x = lon, y = lat), 
            size = 2, color = 'white', fontface = 'bold') +
  scale_color_manual(values = c(rep('tomato', 12)), name = 'Site') +
  labs(
    x = 'Longitude',
    y = 'Latitude'
  ) +
  theme_minimal()

here's what the map looks like now:

是否可以使地图编号方案与图例编号方案相对应?

0 个答案:

没有答案