简体   繁体   中英

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). For some reason I am having problems trying to define the scale in the plot to represent all 3 angles. At the moment only 2 are showing ("B" and "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. 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"))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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