2017-02-18 7 views
0

をcoord_polarする別のgeomを追加し、私は Thのプロットに別のレイヤーを追加したいプロットを持っては以下の通りです。数値が「一致」することを確認するために別の極座標を重ねたいRのggplot2:

以下の例では、虹彩データセットの1つの種類のプロットを作成しています。私はあなたの時間

library(ggplot2) 
library(dplyr) 

mydf <- iris 
plot.data <- tidyr::gather(mydf,key = attribute ,value = avg_score, Sepal.Length:Petal.Width) 


plot.data <- plot.data %>% 
    filter(Species == 'setosa') %>% 
    group_by(attribute) %>% 
    summarise(attr_mean = mean(avg_score)) 

ggplot(plot.data, aes(x=attribute, y = attr_mean, col = attribute)) + 
    geom_bar(stat = "identity", fill = 'white') + 
    coord_polar(theta = "x") + 
    theme_bw() 

答えて

2

これは、物事の非常に歩行者道であるため

ありがとう異なる種の別のプロットをオーバーレイしたいと思います。

plot.setosa <- plot.data %>% 
    filter(Species == 'setosa') %>% 
    group_by(attribute) %>% 
    summarise(attr_mean = mean(avg_score)) 

plot.virginica <- plot.data %>% 
    filter(Species == 'virginica') %>% 
    group_by(attribute) %>% 
    summarise(attr_mean = mean(avg_score)) 

ggplot(plot.setosa, aes(x=attribute, y = attr_mean, col = attribute)) + 
    geom_bar(stat = "identity", fill = 'blue', alpha = 0.25) + 
    geom_bar(data = plot.virginica, stat = "identity", fill= "green", alpha = 0.25, 
      aes(x = attribute, y = attr_mean, col = attribute)) + 
    coord_polar(theta = "x") + 
    theme_bw() 

enter image description here

そしてわずかに少ない歩行者。

xy <- plot.data %>% 
    group_by(Species, attribute) %>% 
    summarise(attr_mean = mean(avg_score)) 

ggplot(xy, aes(x = attribute, y = attr_mean, color = attribute, fill = Species)) + 
    theme_bw() + 
    geom_bar(stat = "identity", alpha = 0.25) + 
    coord_polar(theta = "x") 

enter image description here

+0

ありがとうございました。これはとても巧妙です –