我想轻松地给尼泊尔的地区添加名称。网上大部分答案都是用第二组数据,然后把地图加入到数据中,然后用它来命名点。我没有数据。我只是有一个geojson,有名称栏,纬度,经度等。
nepal_data <- geojson_read("https://raw.githubusercontent.com/mesaugat/geoJSON-Nepal/master/nepal-districts.geojson", what = "sp")
nepal_fort <- tidy(nepal_data)
nepal_plot <- ggplot() +
geom_polygon(data = nepal_fort,
aes(x = long, y = lat, group = group),
fill="blue",
color="white") +
coord_map()
我不知道如何在地图上添加名称。这个问题在某种程度上与 这个 但没有csv数据部分。
当我按原样运行代码时,生成了绘图,但我也得到了。
Unequal factor levels: coercing to characterbinding character and factor vector, coercing into character vectorbinding character and factor vector, coercing into character vectorbinding character and factor.....
我想你要的是直接使用的时候。sf
-包装
library( sf )
library( ggplot2 )
nepal_data <- sf::st_read("https://raw.githubusercontent.com/mesaugat/geoJSON-Nepal/master/nepal-districts.geojson")
ggplot() +
geom_sf( data = nepal_data, fill = "blue", colour = "white" ) +
geom_sf_label( data = nepal_data, aes( label = DISTRICT ), size = 2 )