如何使用 ggplot2 添加背景网格?
我想将背景网格添加到绘图的中心,然后隐藏标准网格线。网格的角点存储在 pts 数据框中,我尝试使用 geom_tile,但它似乎没有使用指定的点。预先感谢您的帮助。
library(ggplot2)
pts <- data.frame(
x=c(170,170,170,177.5,177.5,177.5,185,185,185),
y=c(-35,-25,-15,-35,-25,-15,-35,-25,-15))
ggplot(quakes, aes(long, lat)) +
geom_point(shape = 1) +
geom_tile(data=pts,aes(x=x,y=y),fill="transparent",colour="black") +
opts(
panel.grid.major=theme_blank(),
panel.grid.minor=theme_blank()
)
I'd like to add background grid to the center of the plot and then hide the standard gridlines. The corner points of the grid are stored in the pts data frame and I've tried using geom_tile, but it doesn't appear to use the specified points. Thanks in advance for your help.
library(ggplot2)
pts <- data.frame(
x=c(170,170,170,177.5,177.5,177.5,185,185,185),
y=c(-35,-25,-15,-35,-25,-15,-35,-25,-15))
ggplot(quakes, aes(long, lat)) +
geom_point(shape = 1) +
geom_tile(data=pts,aes(x=x,y=y),fill="transparent",colour="black") +
opts(
panel.grid.major=theme_blank(),
panel.grid.minor=theme_blank()
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以手动指定中断:
那么,这是您想要的吗?
you can manually specify the breaks:
then, is this what you want?
不优雅,但这是我想出的快速而肮脏的东西。不幸的是,我无法在某个点停止这条线,它只是一直延伸到边缘。
Not elegant but this is something quick and dirty that I came up with. Unfortunately I can't stop the line at a certain point, it just goes all the way to the edge.