2015-11-12 4 views
7

Bipartite graph comparisonプロット二部のプラスライングラフの比較

私は2つの異なったランキング法から計算された2位のリストを持っています。 2つのランク付けされたリストの類似性を大まかに定性的に扱うために、このデータをプロットしたいと思います。

私は表示する必要があるデータは、これらの名前のベクトルのようなものである:ここでは

rankMathodA = c(1.5, 4, 7, 3, 4.2) 
names(rankMathodA) = c("Team1", "Team2", "Team3", "Team4", "Team5") 
rankMathodA 
#Team1 Team2 Team3 Team4 Team5 
# 1.5 4.0 7.0 3.0 4.2 

rankMathodB = c(1.7, 3.5, 6.2, 3.9, 4.1) 
names(rankMathodB) = c("Team1", "Team2", "Team3", "Team4", "Team5") 
rankMathodB 
#Team1 Team2 Team3 Team4 Team5 
# 1.7 3.5 6.2 3.9 4.1 
+1

:。http://stackoverflow.com/questions/25781284/simplest-way-to-バッチチャートとスロープグラフの2つの他の引用:http://charliepark.org/a-slopegraph-up​​date/ http:// learnr .wordpress.com/2009/05/06/ggplot2-bump-chart / – lawyeR

答えて

3

は、データの一部の整形とggplot・アプローチのスタートです。 (geom_textを使用したラベルは、テキスト配置を制御するために別々に添加されているあなたは、この便利を見つけるかもしれない

library(reshape2) 
library(ggplot2) 

#create a dataframe with all necessary variables 
dat <- data.frame(team=c("Team1", "Team2", "Team3", "Team4", "Team5"), 
        rankA=c(1.5, 4, 7, 3, 4.2), 
        rankB=c(1.7, 3.5, 6.2, 3.9, 4.1)) 
#turn to long 
dat_m <- melt(dat,id.var="team") 

#plot 
ggplot(dat_m, aes(x=variable, y=value, group=team)) + 
    geom_line() + 
    geom_text(data=dat_m[dat_m$variable=="rankA",],aes(label=team),hjust=1.1) + 
    geom_text(data=dat_m[dat_m$variable=="rankB",],aes(label=team),hjust=-0.1) + 
    geom_vline(xintercept = c(1,2)) + 
    #hide axis, labels, grids. 
    theme_classic() + 
    theme(
    axis.title = element_blank(), 
    axis.line = element_blank(), 
    axis.text = element_blank(), 
    axis.ticks = element_blank()) 

enter image description here