2017-02-18 2 views
0

У меня есть сюжет, который я хочу добавить еще один слой в . Сюжет ниже. Я хочу наложить на него еще один полярный график, чтобы увидеть, что цифры «совпадают»R ggplot2: Добавление другой геометрии в coord_polar

В приведенном ниже примере я создал график для одного вида набора диафрагмы. Я хотел бы наложить еще один участок другого вида

Спасибо за ваше время

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

Спасибо так много. Это очень умно –

Смежные вопросы