8

I have to plot a bipartite graph similar to this one: Bipartite graph comparison

I have 2 ranked list computed from two different ranking method. I would like to plot this data in order to give a rough qualitative handle on the similarity of 2 ranked lists.

The data I need to display is something like these named vectors:

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
zx8754
  • 52,746
  • 12
  • 114
  • 209
andreapavan
  • 697
  • 1
  • 7
  • 24
  • 1
    You might find this useful: http://stackoverflow.com/questions/25781284/simplest-way-to-plot-changes-in-ranking-between-two-ordered-lists-in-r. Plus two other cites for bump charts and slopegraphs: http://charliepark.org/a-slopegraph-update/ http://learnr.wordpress.com/2009/05/06/ggplot2-bump-chart/ – lawyeR Nov 12 '15 at 11:27

1 Answers1

4

Here is a start to a ggplot-approach with some reshaping of data. The labels (using geom_text are added separately to control the text-placement.

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

zx8754
  • 52,746
  • 12
  • 114
  • 209
Heroka
  • 12,889
  • 1
  • 28
  • 38