6

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?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Erin
  • 85
  • 6

3 Answers3

2

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.

m-dz
  • 2,342
  • 17
  • 29
1

Maybe you can use windRose function from open air package

library(openair)
    testsum<-data.frame(Group=c(1,2,3),angle=c(0.78,1.04,2.094),displacement=c(1.5,2,1))
    testsum$angle=180*testsum$angle/pi
windRose(testsum,ws="displacement",wd="angle",breaks=c(0.5,1,1.5,2),paddle=F,key.header = "My Rose",angle=10, 
     statistic="prop.mean",key.footer = "Displacement")

enter image description here

Antonios
  • 1,919
  • 1
  • 11
  • 18
1

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)
MLavoie
  • 9,671
  • 41
  • 36
  • 56