How to fix coord_polar chart

I am trying to build some height data (usually between -90 and 90 degrees) and I managed to use 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 to display negative angles in the plot (I did this by adding 360 degrees to all negative values), but I wonder if there is a better way to do this. Secondly, and, more importantly, I would like to fix (or limit) the output from -90 to 90 degrees, i.e. On the right side of the graph, but I could not do it. Any help on this is welcome.

+4
source share
1 answer

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

enter image description here

This can also be done from -90 to 90 around the entire circle.

enter image description here

For the first:

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

And for the second:

 scale_x_continuous(limits=c(-90,90),breaks=seq(-90, 90, 45)) 
+1
source

Source: https://habr.com/ru/post/1494041/


All Articles