Arn*_*aud 8 r ggplot2 map-projections
我试图在天空上绘制天体(基本上坐标等于纬度/经度).我使用函数的"aitoff"
投影成功绘制了所有点coord_map
,但在这种情况下,网格显示得很糟糕,即仍然显示残差水平线,其中纬度不等于零以及它们的正确投影.
我怎么能删除这些线?
以下是重现行为的代码:
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("","","","","","","","",""))
Run Code Online (Sandbox Code Playgroud)
这绝对是 ggplot2 中的一个错误,所以您可以提交这个错误吗?\n https://github.com/hadley/ggplot2/issues?state=open 归档为错误。
这是一个快速而肮脏的技巧。
\n\nf <- function(x, y, ...) {\n if (any(is.na(x))) {\n id <- rle(!is.na(x))$length\n id <- rep(seq_along(id), id)\n df <- data.frame(x, y, id)\n df <- df[order(df$id, df$x), ]\n } else if (any(is.na(y))) {\n id <- rle(!is.na(y))$length\n id <- rep(seq_along(id), id)\n df <- data.frame(x, y, id)\n }\n polylineGrob(df$x, df$y, id = df$id, gp = gpar(col = "white"))\n}\n\nskyplot2 <- qplot(RA,Dec,data=sky2,xlim=c(0,360),ylim=c(-89.999,89.999),\n xlab="R.A.(\xc2\xb0)", ylab="Decl. (\xc2\xb0)",main="Source repartition on the sky")\nskyplot2 + coord_map(projection="aitoff",orientation=c(89.999,180,0)) + \n scale_y_continuous(breaks=(-2:2)*30,limits=c(-89.999,89.999)) + \n scale_x_continuous(breaks=(0:8)*45,limits=c(0,360),\n labels=c("","","","","","","","","")) +\n opts(panel.grid.major = f)\n
Run Code Online (Sandbox Code Playgroud)\n\n请注意,这可能仅适用于 aitoff 投影。
\n