[英]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.