Map cut on the "edges" of x-axis with Aitoff projection

Viewed 207

I am trying to plot with ggplot2 (v3.3.2) data points on a map using a specific projection (called aitoff), which is useful especially for sky plots.

When doing so, the plot is "cropped" on the x-axis, i.e. the edges of the axis are located just outside the plot. I tried a few things (adjust the margin for example), but without success. Could you please help to make these part of the plot visible?

Here is the code to reproduce the issue, i.e. the point located at (0,0) is not visible.

skydata <- data.frame(RA=c(0,180,360), Dec=c(0,10,20))
ggplot(skydata) + 
    geom_point(aes(RA,Dec)) +
    coord_map(projection="aitoff",orientation=c(90,180,0)) + 
    scale_y_continuous(breaks=(-2:2)*30,limits=c(-90,90)) + 
    scale_x_continuous(breaks=(0:8)*45,limits=c(0,360), labels=c("","","","","","","","","")) +
    labs(x="R.A.(°)", y="Decl. (°)",title="Map of the sky")

I hope I was clear enough... Thanks a lot!

1 Answers

I think that the clipping happens in the first place is a known issue. In the Github issue hadley says: "I think this is a long standing problem that I'm unlikely to solve in the near future"

I think there are two ways, you can more or less solve the problem for yourself. One solution was already mentioned by @Arnaud (but both solutions have downsides)

  1. Add clip = "off" in the coord_map part

  2. Add expand = c(1.1,0) in the scale_x_continuous part

I added you some example plots, where you can see the results and problems.

1. Initial version (if I run your code):

Initial Version

Problem: The point at (0,0) can't be seen properly.

2. Version with expand:

skydata <- data.frame(RA=c(0,180,360), Dec=c(0,10,20))
ggplot(skydata) + 
  geom_point(aes(RA,Dec)) +
  coord_map(projection="aitoff", orientation=c(90,180,0)) + 
  scale_y_continuous(breaks=(-2:2)*30,limits=c(-90,90)) + 
  scale_x_continuous(breaks=(0:8)*45,limits=c(0,360), ,expand = c(1.1, 0), labels=c("","","","","","","","","")) +
  labs(x="R.A.(°)", y="Decl. (°)",title="Map of the sky")

Expand

Looks quite nice now. x-axis got expanded to both sides, point in (0,0) now clearly visible.

But attention seems to work only with natural numbers (like expand = c(5,0)). For the 1.1 I chose in my example the plot is somehow different and the y-axis seems distorted.

3. Version with clip = "off":

skydata <- data.frame(RA=c(0,180,360), Dec=c(0,10,20))
ggplot(skydata) + 
  geom_point(aes(RA,Dec)) +
  coord_map(projection="aitoff", clip = "off", orientation=c(90,180,0)) + 
  scale_y_continuous(breaks=(-2:2)*30,limits=c(-90,90)) + 
  scale_x_continuous(breaks=(0:8)*45,limits=c(0,360), labels=c("","","","","","","","","")) +
  labs(x="R.A.(°)", y="Decl. (°)",title="Map of the sky")

Clip off

This version does not expand the x-axis, but it makes sure, the point at (0,0) is not clipped off. Definitely no distortion of the y-axis. But does not look as good as the solution with expand.

Related