2017-01-10 71 views

回答

0

ggplot2庫的一個可能的解決方案:

library(ggplot2) 
library(reshape2) 

實施例的數據:

df=data.frame(livestock=0.75, 
       tea=0.5, 
       crops=1, 
       carb=0.25, 
       aqua=0.66) 
molten=melt(df) 
> molten 
    variable value 
1 livestock 0.75 
2  tea 0.50 
3  crops 1.00 
4  carb 0.25 
5  aqua 0.66 

簡介:

ggplot(molten, aes(x=seq(1,360,by=360/nrow(molten)),y=value)) + 
    geom_bar(width=360/nrow(molten),stat='identity',position = "stack",colour=("grey90"),aes(fill=variable)) + 
    geom_hline(yintercept = 1 ,linetype="dotted")+ 
    geom_vline(xintercept = seq(37,396,by=360/nrow(molten)),linetype="dotted")+ 
    coord_polar()+ 
    theme_void() 

其中給出:
enter image description here

+0

我用你的例子,發現R的提醒:沒有id變量;使用全部作爲度量變量。我想知道是否應該更改我的數據格式?@Haboryme –

+0

您應該編輯您的原始文章並使用dput()添加您的數據(或其樣本)。對於ggplot2,數據需要採用長格式(許多答案都是用於將數據轉換爲長格式)。 – Haboryme