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.
When based on what the data says, it should look more like this (drawing of intended output).
It seems to be placing the angles incorrectly? Any idea what I am doing wrong?
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:
To clip the bottom half check this answer.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With