geom_sf_text() change position of only one text/label

Hi,

I created this plot

but I would like to change the position of the text "Středočeský."

library(ggplot)
library(sf)
ggplot(data = sf_nezamestnanost) +
  geom_sf(aes(fill = nezamestnanost), colour = "grey10",size=0.2)+
  scale_fill_gradientn(colours= rev(palette))+
  labs(title = "Nezaměstnanost v 1. čtvrtletí 2020",
       fill = "") +
  theme(legend.text.align = 1,
        legend.title.align = 0.5,
        plot.title = element_text(hjust = .1,vjust=0.2,size=18,family="Times"),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_blank(),
        axis.text.x=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks=element_blank(),
        axis.title.x=element_blank(),
        axis.title.y=element_blank())+
  geom_sf_text(aes(label =nazev),size=3,family="sans")+
  ggsave(filename="kraje.png",dpi="print")

Could you help me with that, please?

Thank you

See https://stackoverflow.com/questions/59522531/in-geom-sf-text-how-to-nudge-x-and-y-in-aesthetics and especially the very last remark by Jim Warrell.
This could help you (?)

Sorry, I don't understand the solution provided.

Jakub,

when I read the remark by Jim Warrell in the article mentioned above I thought meant the following.

Because I don't have your data set I use a map of (part of) Europe as an example,
where I want (again as an example and no political intentions :wink: ) to move (nudge)
the text that indicates 'Poland' to another place.
So I

  • plot the map with the default nudges (0)
  • add the nudges (in x and y direction). They are 0 for all data with an exception for Poland.
    To avoid confusion I changed the text for Poland to 'Nudged Poland'
  • plot the map again with my own nudges (called my_nudge_x and my_nudge_y)
library("dplyr")
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library("rnaturalearth")
library("rgeos")
#> Loading required package: sp
#> rgeos version: 0.5-3, (SVN revision 634)
#>  GEOS runtime version: 3.8.0-CAPI-1.13.1 
#>  Linking to sp version: 1.4-1 
#>  Polygon checking: TRUE
library("ggplot2")

world <- ne_countries(scale = "medium", continent='europe',
                      returnclass = "sf")  

ggplot(data = world) +
  geom_sf(aes(fill=admin)) +
  coord_sf(xlim = c(-10, 40), ylim = c(35, 70))  +
  geom_sf_text(aes(label = admin),size=2,family="sans") +
  guides(fill=FALSE)
#> Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
#> give correct results for longitude/latitude data

  

world2 <- world %>%
  mutate(my_nudge_x=ifelse(admin=='Poland',15,0) , 
         my_nudge_y=ifelse(admin=='Poland',5,0) ,
         admin = ifelse(admin=='Poland','Nudged Poland',admin)
  )
   
ggplot(data = world2) +
  geom_sf(aes(fill=admin)) +
  coord_sf(xlim = c(-10, 40), ylim = c(35, 70))  +
  geom_sf_text(aes(label = admin),size=2,family="sans",
               nudge_x=world2$my_nudge_x,nudge_y=world2$my_nudge_y) +
  guides(fill=FALSE)
#> Warning in st_point_on_surface.sfc(sf::st_zm(x)): st_point_on_surface may not
#> give correct results for longitude/latitude data

Created on 2020-07-17 by the reprex package (v0.3.0)

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