2016-12-02 3 views
1

最近のTIMSS reportには、私が出会ったことがあります。私の意見では、非常にコミュニケートなプロットがあります。私はこのようなプロットはクリーブランドドットプロットと呼ばれることを読んだが、これも信頼区間を追加する。私はそれがggplot2またはmatplotlibで再現できるかどうか疑問に思っていました。すべてのヒントは大歓迎です。 plot http://timss2015.org/wp-content/uploads/filebase/science/1.-student-achievement/science-distribution-of-science-achievement-grade-4-table.jpgggplot2のクリーブランドドットプロット

+0

[再現可能な例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)を提供するデータを含めてください。 –

+0

私はプロットのデータは[ここ]です(http://timss2015.org/wp-content/uploads/filebase/science/1.-student-achievement/1_1_science-distribution-of-science-achievement-grade-4)。 xls) –

答えて

2

irisデータセットを使用して:

library(dplyr) 
library(ggplot2) 

plot_data <- iris %>% 
    group_by(Species) %>% 
    summarise_each(funs(mean, sd, n(), q95=quantile(., 0.95), q75=quantile(., 3/4), q25=quantile(., 1/4), q5 = quantile(., 0.05)), Sepal.Length) %>% 
    mutate(se = sd/sqrt(n), 
     left95 = mean - 2*se, 
     right95 = mean + 2*se) 


ggplot(plot_data, aes(x = Species, y = mean)) + 
    geom_crossbar(aes(ymin = q5, ymax = q95), fill = "aquamarine1", color = "aquamarine1", width = 0.2) + 
    geom_crossbar(aes(ymin = q25, ymax = q75), fill = "aquamarine4", color = "aquamarine4", width = 0.2) + 
    geom_crossbar(aes(ymin = left95, ymax = right95), fill = "black", color = "black", width = 0.2) + 
    coord_flip() + 
    theme_minimal() 

enter image description here

は、これはあなたにこれを達成するためにggplot2を使用する方法の要点を与える必要があります。あなたが提供したデータは、dplyrの要約がなくても簡単に使用できます。