0

I am plotting this shapefile and adding countries borders:

library(terra)
 library(ggplot2)
v <- vect(system.file("ex/lux.shp", package="terra"))
ggplot(v) +
geom_spatvector(aes(fill = "NAME_1"), color = "grey")+ borders()+scale_x_continuous(limits = c(4, 8)) + 
  scale_y_continuous(limits = c(48, 52))

There are weird lines, any idea on how to correct this

Tpellirn
  • 660
  • 4
  • 11

1 Answers1

2

The issue is that you set the limits via the scale. If you want to zoom on a region of your plot set the limits via the coord:

library(terra)
library(ggplot2)
library(tidyterra)

v <- vect(system.file("ex/lux.shp", package = "terra"))

ggplot(v) +
  geom_spatvector(aes(fill = "NAME_1"), color = "grey") +
  borders() +
  coord_sf(xlim = c(4, 8), ylim = c(48, 52))

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Thanks, why fill show only one color and not the names under NAME? – Tpellirn Apr 12 '23 at 11:38
  • Remove the quotes. ,i.e. do `fill = NAME_1`. – stefan Apr 12 '23 at 11:43
  • sorry, but in my image from R studio, I got squares instead of circle for the latitude and longitude? What are you using, please? – Tpellirn Apr 12 '23 at 11:52
  • 1
    I'm running RStudio on a Mac. Are you on Windows? In that case the issue is most likely related to the default Windows graphics device which you could check or switch using Tools > Global Options > General > Graphics. See also this related issues: https://stackoverflow.com/questions/74940708/degree-symbol-in-plot-r-with-ggplot2-using-rstudio and https://github.com/r-lib/ragg/issues/51 – stefan Apr 12 '23 at 12:28