ggplot2 geom_boxplot in polar coordinates: 0-180 direction not vertical

ggplot2 geom_boxplot in polar coordinates: 0-180 direction not vertical

我想显示值在方向扇区的箱线图 极坐标,但结果 0 - 180 轴不在垂直方向 方向。为什么? 这就是我所做的:

#Make concentration data (lognormal)
conc <- rnorm(1000,mean=20,sd=5)
conc <- 10^conc
hist(conc)
hist(log10(conc))
#Elements
element <- sample(x=LETTERS[1:3],size=1000,replace=TRUE)
table(element)
#Make distance data
dist <- runif(1000,0.1,50)
#Make orientation data
ang <- rnorm(1000,mean=180,sd=50)
ang[ang<0] <- 0
ang[ang>360] <- 360
hist(ang)
summary(ang)
#Orientation in sectors
angc <- cut(ang,breaks=seq(0,360,by=22.5))
levels(angc) <- as.character(c(0,45,45,90,90,135,135,180,180,225,225,270,270,315,315,0))
#Organize in df
df <-data.frame(ID=as.character(1:1000), 
                element=element,
                distance=dist,
                angle=ang, sector=angc,
                concentration=conc)
head(df)
#plot
p <- ggplot(data=df) + 
  geom_boxplot(aes(x=sector,y=concentration)) +
  scale_y_log10()
p
p + coord_polar() 
p + coord_polar() + facet_wrap(~element)

影子回答后添加: 如果我定义以下间隔:

angc <- cut(ang,breaks=seq(0,360,by=22.5))
angc3 <- angc
levels(angc3) <- c("(338,22.5]", 
                   rep("(22.5,67.5]",2), rep("(67.5,90]",2), rep("(90,135]",2),
                   rep("(135,180]",2),   rep("(180,225]",2), rep("(225,270]",2),
                   rep("(270,338]",2),
                   "(338,22.5]")
df <-data.frame(ID=as.character(1:1000), 
                element=element,
                distance=dist,
                angle=ang, 
                sector=angc3,
                concentration=conc)
p <- ggplot(data=df) + 
    geom_boxplot(aes(x=sector,y=concentration)) +
    scale_y_log10()

p + coord_polar()

现在338,22.5这个区间的中心是0,但是还没有处于垂直位置。我想我不明白你说:"it normally starts at the top and then distributes sectors equally"。 (338,22.5] 应该在顶部。

当您使用具有离散 x 轴的函数 coord_polar 时,它通常从顶部开始,然后平均分配扇区。然后,中断位于扇区的中间,而不是从顶部开始。在你的情况下,你知道你将有 8 次休息,所以你可以将起点移动 pi/8(开始以弧度为单位)

p + coord_polar(start=-pi/8)