2014-10-01 79 views
0

我想根據圓角/方向(0-360度)使用極座標圖來表示頻率。出於某種原因,我在試圖定義劇情中的比例以表示所有3個角度時遇到了問題。目前只有2個顯示(「B」和「C」)。任何幫助將不勝感激。在此先感謝,使用角度數據在極座標圖上繪製頻率ggplot2

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

回答

0

geom_bar中的寬度是問題。以下工作:

ggplot(分貝)+ geom_bar(STAT = 「同一性」,顏色= 「grey100」,AES(X =角,Y = PERC,填充= STAT,寬度= 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」))

enter image description here

+0

的問題,我有與設置正確的刻度來表示角度全圓(0-360)並將這些角度標記爲方向(例如「N」,「S」,「W」,「E」等)。 – user1626688 2014-10-01 03:00:55

+0

請參閱我上面更正的答案。 – rnso 2014-10-01 04:22:14

+0

我仍然覺得有什麼問題。當我嘗試其他「角度」(從0/360分散更大)時,我可以使用更大的寬度。奇怪的是,用這個特定角度1我必須調整寬度。 – user1626688 2014-10-01 05:29:09