Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rose diagram for migration data

I am trying to create a rose diagram showing average trajectory angle and distance for each subset of cells. I want the angle around the rose diagram to be the trajectory angle and the length of the bar in the diagram to be the total displacement.

Here is a test data set of the mean angle and displacement per group.

testsum<-data.frame(Group=c(1,2,3),
                angle=c(0.78,1.04,2.094),
                displacement=c(1.5,2,1))

When I try to plot this in a circular method, my chart looks very wrong.

p1<-ggplot(testsum, aes(x=angle,y=displacement))+
  coord_polar(theta="x",start=0)+
  geom_bar(stat="identity",aes(color=Group,fill=Group),width=.01)+    
  scale_x_continuous(breaks=seq(0,360,60))

It gives me this graph for output.

enter image description here

When based on what the data says, it should look more like this (drawing of intended output). enter image description here

It seems to be placing the angles incorrectly? Any idea what I am doing wrong?

like image 777
Erin Avatar asked Feb 14 '18 20:02

Erin


2 Answers

Although MLavoie "beat me" by 20 minutes, I think some readibility can be added by using NISTunits package:

library(ggplot2)
library(NISTunits)

testsum <- data.frame(
  Group = c(1, 2, 3),
  angle = c(0.78, 1.04, 2.094),
  displacement = c(1.5, 2, 1)
)

testsum$angle = NISTradianTOdeg(testsum$angle)

ggplot(testsum, aes(x = angle, y = displacement)) +
  coord_polar(theta = "x", start = NISTdegTOradian(-90), direction = 1) +
  geom_bar(stat = "identity",
           aes(color = Group, fill = Group),
           width = 1) +
  scale_x_continuous(breaks = seq(0, 360, 10), limits = c(0, 360))

Result:

enter image description here

To clip the bottom half check this answer.

like image 106
m-dz Avatar answered Oct 16 '22 18:10

m-dz


Maybe you can try this:

testsum$angle_b=180*testsum$angle/pi
#
ggplot(testsum, aes(x=angle_b,y=displacement))+
    geom_bar(stat="identity",aes(color=Group,fill=Group),width=1) +    
    scale_x_continuous(breaks=seq(0,360,10), limits=c(0,360)) + coord_polar(direction=1)
like image 26
MLavoie Avatar answered Oct 16 '22 16:10

MLavoie