我正在尝试在天空上绘制天体(基本上坐标相当于纬度/经度)。我使用 coord_map
函数的 "aitoff"
投影成功绘制了所有点,但在这种情况下,网格显示效果很差,即仍然显示剩余水平线纬度不等于零及其正确的投影。
如何删除这些行?
下面是重现该行为的代码:
library(ggplot2)
library(mapproj)
sky2 = data.frame(RA=0, Dec=0)
skyplot2 <- qplot(RA,Dec,data=sky2,xlim=c(0,360),ylim=c(-89.999,89.999),
xlab="R.A.(°)", ylab="Decl. (°)",main="Source repartition on the sky")
skyplot2 + coord_map(projection="aitoff",orientation=c(89.999,180,0)) +
scale_y_continuous(breaks=(-2:2)*30,limits=c(-89.999,89.999)) +
scale_x_continuous(breaks=(0:8)*45,limits=c(0,360),
labels=c("","","","","","","","",""))
最佳答案
这肯定是 ggplot2 中的一个错误,所以您能提交这个错误吗?
https://github.com/hadley/ggplot2/issues?state=open Filed as a bug .
这是一个快速而肮脏的技巧。
f <- function(x, y, ...) {
if (any(is.na(x))) {
id <- rle(!is.na(x))$length
id <- rep(seq_along(id), id)
df <- data.frame(x, y, id)
df <- df[order(df$id, df$x), ]
} else if (any(is.na(y))) {
id <- rle(!is.na(y))$length
id <- rep(seq_along(id), id)
df <- data.frame(x, y, id)
}
polylineGrob(df$x, df$y, id = df$id, gp = gpar(col = "white"))
}
skyplot2 <- qplot(RA,Dec,data=sky2,xlim=c(0,360),ylim=c(-89.999,89.999),
xlab="R.A.(°)", ylab="Decl. (°)",main="Source repartition on the sky")
skyplot2 + coord_map(projection="aitoff",orientation=c(89.999,180,0)) +
scale_y_continuous(breaks=(-2:2)*30,limits=c(-89.999,89.999)) +
scale_x_continuous(breaks=(0:8)*45,limits=c(0,360),
labels=c("","","","","","","","","")) +
opts(panel.grid.major = f)
请注意,这可能仅适用于 aitoff 投影。
关于r - 使用 ggplot2 网格显示不良,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10706632/