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.