0

I wish to rotate a ggplot2 map annotation. At this moment, through the following line:

annotate("rect", xmin=c(-8.5), xmax=c(-9), ymin=c(42.1) , ymax=c(42.35), alpha=0.2, color="black")

I achieved to create this map:

enter image description here

Despite this, what I'm looking for is the next:

enter image description here

Do you have any idea on how to achieve it?

Many thanks in advance!

Note: here is the full ggplot code for this map:

ggm2 <- ggplot() +
  theme_bw() + 
  geom_sf(data = eu) +
  geom_sf(data = Spain) +
  xlab("") +
  ylab("") +
  #xlab("Longitude") + ylab("Latitude") + 
  coord_sf(xlim = c(-10.5, -6.5), ylim = c(41.5, 44.5), expand = FALSE) + 
  annotation_scale(location = "bl", width_hint = 0.5) +
  annotate(geom = "text", x = -9.3, y = 44, label = "Atlantic Ocean", 
           fontface = "italic", color = "grey22", size = 6, angle=35) + 
  annotate(geom = "text", x = -7.75, y = 41.65, label = "Portugal", 
           fontface = "italic", color = "grey22", size = 5) + 
  annotation_north_arrow(location = "bl", which_north = "true", 
                         pad_x = unit(0.65, "in"), pad_y = unit(0.5, "in"),
                         style = north_arrow_fancy_orienteering) +
  annotate("rect", xmin=c(-8.5), xmax=c(-9), ymin=c(42.1) , ymax=c(42.35), 
           alpha=0.2, color="black")
edusanlla
  • 23
  • 5
  • Would the answer to this question help? (https://stackoverflow.com/questions/27585588/how-to-rotate-only-text-in-annotation-in-ggplot)[https://stackoverflow.com/questions/27585588/how-to-rotate-only-text-in-annotation-in-ggplot] – Wolfgang Arnold Jun 02 '21 at 10:59
  • Sorry, I think that the link is broken, could you post it again? – edusanlla Jun 02 '21 at 11:18
  • Weird - maybe I screwed up the comment-formatting - next try: https://stackoverflow.com/questions/27585588/how-to-rotate-only-text-in-annotation-in-ggplot – Wolfgang Arnold Jun 02 '21 at 12:57
  • Unfortunately not, the function rotate works when dealing with text but not when applied to polygons or these kinds of annotations – edusanlla Jun 03 '21 at 15:12

1 Answers1

1

One way to do it would be to draw a polygon using geom_polygon, in this way you are able to draw any shape you want and not just rectangles.

library(ggplot2)
library(maps)

world1 <- sf::st_as_sf(map('world', plot = FALSE, fill = TRUE))

data_poly <- data.frame(
  x = c(-84,-82,-84,-86),
  y = c(26, 28, 30, 28)
)

ggplot(data = world1) +
  theme_bw() + 
  geom_sf() +
  coord_sf(xlim=c(-88, -78), ylim=c(24.5, 33), expand=FALSE) +
  geom_polygon(data=data_poly, aes(x=x,y=y), fill='black', color='black', alpha=.1)