4

I'm trying to plot some elevation data (usually between -90 and 90 degrees), and I have succeeded somewhat using coord_polar. Take a look at this code:

library(ggplot2)
#
r = c(2:8)*20
e = c(-4:9)*10
a = c(0:71)*5

points = expand.grid(r,e,a)
colnames(points) = c("distance", "elevation", "azimuth")
points$elevation[points$elevation <0] = points$elevation + 360

forEle = subset(points, azimuth == 0)


#ele_range = 
ggplot(forEle, aes( x=elevation, y=distance))+
geom_point()+
coord_polar(theta = "x", start = -1.5708, direction = -1)+
scale_y_continuous(breaks = c(0:16)*10, limits=c(0, 160)) +
scale_x_continuous(breaks=seq(0, 359, by=30), labels=c(expression(0^degree), expression(30^degree), expression(60^degree), expression(90^degree), expression(60^degree), expression(30^degree), expression(0^degree), expression(-30^degree), expression(-60^degree), expression(-90^degree), expression(-60^degree), expression(-30^degree)), limits=c(0, 360)) +
labs(title = "",
        x = "x",
        y = "y")+
theme(legend.position="bottom")

My first difficulty was trying to map negative angles to the plot (I did it by adding 360 degrees to all negative values), but I wonder if there's a better way to do that. Second, and more important, I'd like to clip (or limit) the output from -90 to 90 degrees, i.e., the right side of the plot, but I haven't been able to do it. Any help on this issue is appreciated.

Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
julovi
  • 83
  • 8
  • Do you have a sample dataset with can be used to replicate the issue (and test a solution)? Also, re: the output clipping, have you tried `xlim()`? – metasequoia Jul 29 '13 at 12:55
  • hi, thanks, answering your first question, the code I provided creates a plot from 0 to 360 degrees, what I want is to have the same plot but "zoomed-in" from -90 to 90 degrees. As for your 2nd question, yes, I tried xlim() without success. – julovi Jul 29 '13 at 14:48
  • @julovi : By zoomed in, do you mean that you only want the right side of the plot to contain points, or do you mean that the radial variable should range from -90 to 90? – mitchus Jul 29 '13 at 15:44
  • I mean that the angular variable should range from -90 to 90. The radial variable, doesn't matter. – julovi Jul 29 '13 at 15:48

1 Answers1

1

I'm a bit late to the party, but you mean something like this?

enter image description here

It can also be done with -90 to 90 around the whole circle.

enter image description here

For the first one:

scale_x_continuous(limits=c(-180,180),breaks=seq(-90, 90, 45))

And for the second one:

scale_x_continuous(limits=c(-90,90),breaks=seq(-90, 90, 45))
  • Thanks! although it's not exactly what I asked, your plots are still showing a full circle, and I want to clip the output "from north to south pole" only. – julovi May 22 '14 at 02:20
  • You can adjust where the zero point starts from by adding start=some angle to coord_polar(), but you can't clip any part of the circle out. You have to use an image editing program to cut out half the circle if you want a semi-circle. – Christie Haskell Marsh Jul 24 '14 at 21:34
  • 1
    Actually, apparently you can: http://stackoverflow.com/questions/22398350/how-to-show-only-part-of-the-plot-area-of-polar-ggplot-with-facet/22418817#22418817 – Christie Haskell Marsh Jul 27 '14 at 15:21