11

我想知道是否有办法让 ggplot 在绘制的数据前面绘制其网格线。据我所知,我可以使用目前运行良好的主题()轻松格式化几乎所有内容。但是,我找不到元素绘制顺序的选项。我可以在绘图中引入额外的线,这些线需要事先格式化(坐标、线组等)。听起来更复杂,因为它需要。所以我希望,我可以修改绘图网格本身来完成这项工作。

我通常如何绘制sf.df加载的 shapefile 的数据框的示例sf

(ggplot(sf.df, aes(x=long, y=lat))
+ geom_polygon(data=sf.df, aes(group=group, fill=NFK))
+ theme(panel.grid.major=element_line(colour="black"))
+ coord_map(xlim=c(7.08, 7.14), ylim=c(50.93, 50.96))
)

先感谢您!

4

1 回答 1

11

正如@joran 建议的那样,使用geom_hlineandgeom_vline绝对是一种解决方案。简单定义yinterceptxintercept分别像这样:

...
+ geom_vline(xintercept=seq(7.08, 7.14, by=0.01))
+ geom_hline(yintercept=seq(50.93, 50.96, by=0.01))
...
于 2013-09-29T10:29:19.947 回答