Grid does not display well with ggplot2

I am trying to build a celestial object in the sky (mostly with coordinates equivalent to latitude / longitude). I successfully built all my points using the "aitoff" projection of the "aitoff" function, but in this case the grid is not displayed well, i.e. residual horizontal lines are still displayed for non-zero latitudes, along with their correct projections.

enter image description here

How can I delete these lines?

Here is the code that reproduces the behavior:

 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="RA(Β°)", 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("","","","","","","","","")) 
+8
r ggplot2 map-projections
source share
2 answers

This is definitely a bug in ggplot2, so please write this bug? https://github.com/hadley/ggplot2/issues?state=open Filed as an error .

Here is a quick and dirty hack.

 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="RA(Β°)", 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

Please note that this can only work with aitoff projection.

+4
source share

You just need to add:

 + opts(axis.ticks = theme_blank()) 
+2
source share

All Articles