我已經創建了加拿大紐芬蘭的地圖,并希望突出顯示三一灣。我試圖使用geom_rect. 它對我有用(紅色矩形),盡管我想旋轉矩形使其只包含海灣,而不包含周圍的土地(如橙色矩形)。
這是我的代碼:
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
有什么建議?提前致謝!
uj5u.com熱心網友回復:
使用geom_polygon()代替_rect()。定義引數并傳入。它需要使用引數,但很容易做到 - 我的機器正在播放,并且需要很長時間才能按照您的意愿將其從托架中取出。
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)

uj5u.com熱心網友回復:
這里沒有專家,但你能也許使用的引數hjust和vjust內geom_rect?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/368698.html
上一篇:如何將行合并到R中的列中?
