【发布时间】:2021-11-14 16:07:35
【问题描述】:
因此,基于this post,我使用 ggplot 创建了纽约市行政区的地图
我有一个看起来像这样的数据集,称为boroughs_personal
borough count
Brooklyn 211
Manhattan 12
Queens 1
所以我将它加入到地图数据中,类似于上面的帖子,它就像一个梦一样工作。
# download and extract data
bb <- getbb("New York City, New York")
boundaries <- opq(bbox = bb) %>%
add_osm_feature(key = "boundary", value = "administrative") %>%
osmdata_sf() %>%
unname_osmdata_sf()
boroughs <- boundaries[["osm_multipolygons"]] %>%
filter(name %in% c("Manhattan", "The Bronx", "Brooklyn", "Queens", "Staten Island")) %>%
left_join(boroughs_personal , by = c('name' = 'borough'))
ggplot() +
geom_sf(data = boroughs, aes(fill = count))+
##guides(fill=FALSE) +
scale_fill_continuous(low = "lightblue", high = "darkblue")+
theme(axis.title.x=element_blank(), axis.text.x=element_blank(), axis.ticks.x=element_blank(),
axis.title.y=element_blank(), axis.text.y=element_blank(), axis.ticks.y=element_blank()) +
ggtitle('New York Boroughs ')
但我需要将count 变量的标签添加到每个行政区。我该怎么做???
【问题讨论】:
-
geom_sf_text(aes(label = count), colour = "white")我试过这个但没有用@camille -
为什么?发生什么了?无需安装和下载所有内容即可查看您正在查看的内容会很有帮助
-
@camille 这是错误
Don't know how to automatically pick scale for object of type function. Defaulting to continuous. Error: Aesthetics must be valid data columns. Problematic aesthetic(s): label = count. Did you mistype the name of a data column or forget to add after_stat()?