2012-05-22 25 views
8

空に天体をプロットしようとしています(基本的に緯度/経度に相当する座標で)。私はcoord_map関数の"aitoff"投影を使用してすべてのポイントをうまくプロットしましたが、この場合、グリッドはひどく表示されます。つまり、正確な投影とともに零以外の余分な水平線が表示されます。ggplot2を使ってグリッドがひどく表示される

enter image description here

どのように私はこれらの行を削除するだろうか?ここで

が動作を再現コードです:

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("","","","","","","","","")) 

答えて

4

確かにこれはそう、あなたがこのバグを報告してください可能性がggplot2のバグですか? https://github.com/hadley/ggplot2/issues?state=openFiled 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) 

enter image description here

これが唯一エイトフ図法で動作してもよいことに留意されたいです。

2

あなただけ追加する必要があります。

+ opts(axis.ticks = theme_blank()) 
+0

Hmm。これは、図の下部にあるダニを取り除きますが、OPが除去したい余分な(直線の)水平線は除去しません。 –

+0

oh woops。疑問を十分に読まなかった。 –

関連する問題