Pink chart in R

I want to draw a pink chart of some pie data. I used the circular package, and in this package it allows you to draw a simple rose diagram using the function: rose.diag . Despite the fact that this draws a chart, I want to be able to improve the graphics, but I can not find to add to the chart or modify it a little. I looked at how to draw it in ggplot2 but ggplot2 is not entirely clear, and I struggle ggplot2 find another package in R that draws similar rose diagrams.

I am posting below a sample of the data and my current code along with my requests:

 Angle 0.65454759 0.01355458 0.5052027 0.2264302 -0.350552 -0.428481 0.1231778 0.258787 0.06723504 0.06906181 2.54608572 -1.6591672 3.00437314 -0.0503291 -0.828578 -1.9616418 -0.6468774 0.01438686 0.1162713 0.9938797 0.1861583 0.1547071 0.2577813 0.5110576 0.08714113 

These data are radial rotation angles. Using the circular package, I make this data a vector of the circular class:

 x <- circular(Angle) 

Then draw a rose diagram using the following code, where it represents the diagram in degrees, not in radians:

 rose.diag(x, pch = 16, cex = 1, axes = TRUE, shrink = 1, col=3, prop = 2, bins=36, upper=TRUE, ticks=TRUE, units="degrees") 

There are 3 things I would like to add to this plot:

  1. Change the orientation of the graph so that 0 is on top and not on the right.
  2. Add concentric circles to the graph to help with the visual interpretation of the size and weight of each basket.
  3. Add a line to determine the average angle (if possible, with sd errors)
+4
source share
1 answer

There are several ways to do this. There is a null argument to rose.diag in this package.

 y <- scan() # paste in the values from the question and hit return twice y <- circlar(y) # not necessary but prevents a warning rose.diag(y, units = 'degrees', zero = pi/2) # units doesn't change the underlying units 

Alternatively, you could set the properties of the created circular object.

 y <- circlar(y, zero = pi/2) rose.diag(y, units = 'degrees') # note, no 0 call here 

So now the chart is spinning ... how to add material ...

 > par('usr') [1] -1.376553 1.376553 -1.123200 1.123200 

This gives me the coordinates of the user and tells me the plot sizes in user space. Now I can do things like adding a circle.

 symbols(0, 0, circle = 0.2, inches = FALSE, add = TRUE, fg = 'red') 

There is a lines.circular function, but it was not obvious to me how to use it. I could also draw a line using the segments or arrows and draw directly on the chart with them. Converting the angle and length of the line to points requires a little Euclidean geometry. It all has to start.

 m <- mean.circle(y) segments(0, 0, cos(m+pi/2), sin(m+pi/2), col = 'red') # note I need to add the new 0 position... there is a lines.circular function but it wasn't obvious to me how to use it. 

(tip ... the cropping circle in rose.diag is in radius 1, so that the circle argument in symbols will draw exactly at this point)

+3
source

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


All Articles