I have created a map of Newfoundland, Canada and wish to highlight Trinity Bay. I was trying to do this using geom_rect
. It is working for me (red rectangle), although I would like to rotate the rectangle so that it contains just the bay, and none of the surrounding land (like the orange rectangle).
Here is my code:
library(ggplot2)
Provinces <- getData("GADM", country="CAN", level=1)
d <- ggplot()
geom_polygon(data=Provinces, aes(long, lat, group=group), colour="grey10",
fill="cadetblue1", alpha=0.8)
coord_map(xlim=c(-60, -52), ylim=c(46, 52))
theme_bw()
geom_rect(aes(xmin=-53, xmax=-53.75, ymin= 47.5, ymax=48.5), alpha=0,
colour="red", size=1, linetype=1)
d
Any suggestions? Thanks in advance!
CodePudding user response:
Use geom_polygon()
instead of _rect()
. Define the parameters and pass in. It requires playing around with the parameters, but is easy to do - My machine is playing up, and it's taking too long to get it over the bay as you want.
poly <- tibble(x = c(-53.75, -53, -52, -52.75), y = c(47.5, 47.5, 48.5, 48.5))
d <- ggplot()
geom_polygon(data=Provinces, aes(long, lat, group=group), colour="grey10", fill="cadetblue1", alpha=0.8)
coord_map(xlim=c(-60, -52), ylim=c(46, 52))
theme_bw()
geom_polygon(data = poly, aes(x = x, y = y), alpha=0, colour="red", size=1, linetype=1)
CodePudding user response:
Not an expert here but could you perhaps use the arguments hjust
and vjust
within geom_rect
?