繁体   English   中英

使用角度数据ggplot2在极坐标图上绘制频率

[英]Plot frequencies on a polar plot using angle data, ggplot2

我正在尝试使用极坐标图来表示根据圆角/方向(0-360度)的频率。 由于某些原因,我在尝试定义绘图中的比例以表示所有3个角度时遇到问题。 目前仅显示2个(“ B”和“ C”)。 任何帮助将不胜感激。 提前致谢,

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)) 

问题是geom_bar中的宽度。 以下作品:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM