Shab
Shab

Reputation: 1

Query About How To Generate Vietnam Map With Custom Labels For Each Province R Script

I want to generate the Vietnam Map using an R script which I have done but I cant figure out how to generate the map with custom labels.

My Script:What It Generates

library(ggplot2)
library(tidyverse)
library(sp)
library(raster)
library(rgdal)
library(viridis)
library(readxl)
library(maptools)

vnm = getData("GADM", country="Vietnam", level=1)
vn = fortify(vnm,region = "VARNAME_1")
ggplot(data=vn, aes(x=long, y=lat, group=group)) + geom_polygon(aes(fill=id), col="black", show.legend=T)+theme_void()

What I Want To Label

Upvotes: 0

Views: 268

Answers (1)

Robert Hijmans
Robert Hijmans

Reputation: 47146

I am not sure what you mean with "custom labels". Do want different values in the legend, or do you want labels on the map?

Here is a simple example to get started

library(terra)
library(geodata)

lux = gadm("Luxembourg", level=1, path=".")
plot(lux, "NAME_1", main="")
text(lux, paste0("(", 1:nrow(lux), ")"), halo=TRUE, pos=1, cex=1.2)
text(lux, "NAME_1", halo=TRUE, cex=0.8, pos=3)

enter image description here

Upvotes: 0

Related Questions