Labelling a Map - nominal variable

Hello there

I am creating a map showing the membership status of Mercosur trade bloc and I would like to label the countries to show their names and, if possible, their capitals as well. However, I am doing something wrong that the countries' names appear on the borders and not on the centroids.

The code that is working is below but doesn't include the countries nor the capitals.

Thank you in advance

plot Membership

p <- ggplot ()+

first layer: all countries, no fill, no white outlines

geom_polygon(data = South.maps,
aes(x = long, y = lat, group = group)) +
#second layer: only countries with a fill
geom_polygon(data = MSRmap,
aes(x = long,
y = lat,
group = group,
fill = Membership), colour = "white") +
scale_colour_discrete_qualitative() +
theme_minimal() +
labs(fill = "Membership status",
x = "",
y = "") +
ggtitle("Mercosur members (2020)") +
scale_y_discrete(breaks=c()) + # this is to remove scales from y axis
scale_x_discrete(breaks=c()) + # this is to remove scales from x axis
theme(plot.title = element_text(hjust = 0.5))

p # show the graph

Hi!

We don't really have enough information in your question. In particular, we don't have the data you are using to make your plot. To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

That being said, here is an example of how you might label polygons, using a built in dataset in the sf package.

library(sf)
library(ggplot2)

nc <- read_sf(system.file("shape/nc.shp", package = "sf"))
ggplot(nc) +
  geom_sf() +
  geom_sf_text(aes(label = NAME), size = 3)

Created on 2020-06-09 by the reprex package (v0.3.0)

I appreciate your reply and I apologise for not providing the necessary information. Indeed, I am learning R in the last few months and I do not know all the necessary steps
However, I managed to find the solution, as seen below

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.