[英]Plot frequencies on a polar plot using angle data, ggplot2
I am trying to use a polar plot to represent frequencies according to a circular angle/direction (0-360 degrees). 我正在尝试使用极坐标图来表示根据圆角/方向(0-360度)的频率。 For some reason I am having problems trying to define the scale in the plot to represent all 3 angles. 由于某些原因,我在尝试定义绘图中的比例以表示所有3个角度时遇到问题。 At the moment only 2 are showing ("B" and "C"). 目前仅显示2个(“ B”和“ C”)。 Any help will be appreciated. 任何帮助将不胜感激。 Thanks in advance, 提前致谢,
library(ggplot2)
data <- read.table(text = "stat angle freq perc
A 1 720 79
B 223.5017 121 13
C 117.9372 68 7", header=T)
head(data)
str(data)
db<-data
db$stat<-factor(db$stat)
levels(db$stat)
# Plot
bp<-ggplot(db, aes(x = angle, y = perc), fill = factor(stat)) +
geom_bar(stat="identity", colour="grey100", aes(fill = factor(stat),
width = 16)) +
coord_polar(theta="x", start=0) +
theme_minimal() + ylab("Detections (%)") +
scale_x_continuous("", lim=c(0,360), breaks = seq(0, 315, 45),
labels = c("N","NE","E","SE","S","SW","W","NW"))
bp2<-bp + theme(panel.grid.major = element_line(colour = "grey60", size=0.45),
panel.grid.minor = element_line(colour = "grey60", size=0.45))
Width in geom_bar is the issue. 问题是geom_bar中的宽度。 Following works: 以下作品:
ggplot(db) +
geom_bar(stat="identity",
colour="grey100",
aes(x = angle, y = perc, fill = stat, width = 2)) +
coord_polar() +
theme_minimal() +
ylab("Detections (%)")+
scale_x_continuous(limits=c(0,360),
breaks = seq(0, 315, 45),
labels = c("N","NE","E","SE","S","SW","W","NW"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.