This appeared to be an issue with the package rather than the code. Upon uninstalling and reinstalling the circular package the axis labels read in a clockwise direction when using the commands listed above.
How to change the axis label direction on a circular plot in R
Question
I have some angular data (on a scale of 0°
-360°
). I have successfully created a circular plot using the 'circular' package in R
, but the axis labels read in an anticlockwise direction, rather than clockwise.
I need to rectify this as the data and axis labels are currently mismatched. The labels should run from 0°
-345°
in a clockwise direction.
Here is the R
code that I used to create the plot:
library(circular)
# Create circular object / Sample Data
df <- structure(c(345, 355, 351, 359, 358, 359, 359, 357, 352, 3, 6,
4, 342, 336, 349, 352, 340, 354, 335, 348, 355, 353, 354, 346,
351, 359, 358, 357, 348, 336, 349, 351, 355, 354, 356), .Dim = c(35L,
1L), .Dimnames = list(NULL, "Bearing"), circularp = structure(list(
type = "angles", units = "degrees", template = "none", modulo = "2pi",
zero = 0, rotation = "clock"), .Names = c("type", "units",
"template", "modulo", "zero", "rotation")), class = c("circular",
"matrix"))
# circular mean
m.p = mean(df)
# mean vector length
rho.p = rho.circular(df)
# label seq for axes values
p.axis = seq(0,345, by=15)
# axis intervals
a.p <- circular(p.axis, units='degrees', modulo="2pi", rotation="clock")
par(mfrow=c(1,1), mar=c(0,0,0,0))
plot(df,
stack=TRUE,
bins=60,
col="mediumseagreen",
pch=16,
tcl=0.04,
tcl.text=0.125,
axes=FALSE,
cex=1.4,
shrink=1.3,
sep=0.05,
xlim = c(0, 1.2),
ylim = c(-1, 1))
# add axis
axis.circular(a.p, labels=p.axis, cex=0.9)
# add kernel density estimate
lines(density(df, bw=20), col='mediumseagreen', lty=2, lwd=1.5)
# arrow to indicate direction of circular mean, scaled by mean vector length
arrows.circular(m.p, shrink=rho.p, length=0.15, col='mediumseagreen', lwd=2.5)
I’ve tried fiddling with the code, and have had no luck.
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow