Home > Back-end >  How to format custom polar.plot labels in R
How to format custom polar.plot labels in R

Time:08-15

I want to customize the labels of a polar.plot in R.

I have the following plot:

polar.plot(lengths = 0.4, polar.pos =33, 
           main= "Richting en magnitude van de waterstroom", labels = ?, 
           start=90, clockwise = TRUE, loglen=FALSE, explab=FALSE, 
           rp.type="r", lwd = 4, line.col = "blue")

I want to add custom labels to the outer circle, with certain values at certain degrees and nothing else.

the labels are:

c("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8")

and the angles would be every 45 degrees, so:

c(0,45,90,135,180,225,270,315)

However, I can't seem to find out how to correctly format this to fill it in the argument 'labels = x' in the plot. i have treid filling in the labels string under labels = x and the angles string under label.pos = x as follows:

(colnames = c("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8"))

polar.plot(lengths = magnitude, polar.pos =degrees, 
           main= "Richting en magnitude van de waterstroom", 
           labels = colnames, 
           label.pos = c(0,45,90,135,180,225,270,315), 
           start=90, clockwise = TRUE, loglen=FALSE, explab=FALSE, 
           rp.type="r", lwd = 4, line.col = "blue") 

However, this does not give the desired effect. the labels are all there, and t1 is at 0 degrees, but after that something goes wrong.

CodePudding user response:

You could specify the position of the labels using label.pos and you should divide the numbers by (180/pi) like this:

positions of the peripheral labels in degrees

Code:

library(plotrix)
polar.plot(lengths = 0.4, polar.pos=33, 
           main= "Richting en magnitude van de waterstroom", 
           labels = c("t1", "t2", "t3", "t4", "t5", "t6", "t7", "t8"), 
           label.pos = c(0,45,90,135,180,225,270,315)/(180/pi),
           start=90, clockwise = TRUE, 
           loglen=FALSE, explab=FALSE, 
           rp.type="r", lwd = 4, line.col = "blue")

Created on 2022-08-15 by the reprex package (v2.0.1)

  • Related