This post is the replication of this blog post; slight tweaks are done to make it more visual.
df <- structure(list(Horse = structure(c(11L, 16L, 13L, 15L, 3L, 18L, 10L, 17L, 19L,
8L, 5L, 9L, 1L, 4L, 12L, 2L, 14L, 7L, 6L), .Label = c("Advice",
"Atomic Rain", "Chocolate Candy", "Desert Party", "Dunkirk", "Flying Private", "Friesan Fire",
"General Quarters", "Hold Me Back", "Join in the Dance", "Mine That Bird", "Mr. Hot Stuff",
"Musket Man", "Nowhere to Hide", "Papa Clem", "Pioneer of the Nile", "Regal Ransom", "Summer Bird",
"West Side Bernie"), class = "factor"), X1.4 = c(19L, 3L, 8L, 5L, 17L, 16L, 1L, 2L, 13L, 12L, 9L,
14L, 15L, 4L, 18L, 10L, 11L, 6L, 7L), X1.2 = c(19L, 3L, 8L, 4L, 12L, 16L, 1L, 2L, 17L, 13L, 10L,
5L, 15L, 6L, 18L, 9L, 14L, 7L, 11L), X3.4 = c(19L, 4L, 7L, 3L, 15L, 16L, 1L, 2L, 14L, 11L, 9L, 6L,
17L, 5L, 18L, 10L, 12L, 8L, 13L), X1m = c(12L, 2L, 7L, 4L, 8L, 15L, 1L, 3L, 17L, 10L, 11L, 5L, 13L,
6L, 16L, 9L, 18L, 14L, 19L), Str = c(1L, 2L, 4L, 3L, 7L, 9L, 5L, 6L, 13L, 10L, 12L, 8L, 14L, 11L, 16L,
15L, 18L, 17L, 19L), Finish = 1:19), .Names = c("Horse", "X1.4", "X1.2", "X3.4", "X1m", "Str", "Finish"),
class = "data.frame", row.names = c(NA, -19L))
df
## Horse X1.4 X1.2 X3.4 X1m Str Finish
## 1 Mine That Bird 19 19 19 12 1 1
## 2 Pioneer of the Nile 3 3 4 2 2 2
## 3 Musket Man 8 8 7 7 4 3
## 4 Papa Clem 5 4 3 4 3 4
## 5 Chocolate Candy 17 12 15 8 7 5
## 6 Summer Bird 16 16 16 15 9 6
## 7 Join in the Dance 1 1 1 1 5 7
## 8 Regal Ransom 2 2 2 3 6 8
## 9 West Side Bernie 13 17 14 17 13 9
## 10 General Quarters 12 13 11 10 10 10
## 11 Dunkirk 9 10 9 11 12 11
## 12 Hold Me Back 14 5 6 5 8 12
## 13 Advice 15 15 17 13 14 13
## 14 Desert Party 4 6 5 6 11 14
## 15 Mr. Hot Stuff 18 18 18 16 16 15
## 16 Atomic Rain 10 9 10 9 15 16
## 17 Nowhere to Hide 11 14 12 18 18 17
## 18 Friesan Fire 6 7 8 14 17 18
## 19 Flying Private 7 11 13 19 19 19
library(reshape2)
library(ggplot2)
df$Horse <- with(df, reorder(Horse, Finish))
dfm <- melt(df)
## Using Horse as id variables
head(dfm)
## Horse variable value
## 1 Mine That Bird X1.4 19
## 2 Pioneer of the Nile X1.4 3
## 3 Musket Man X1.4 8
## 4 Papa Clem X1.4 5
## 5 Chocolate Candy X1.4 17
## 6 Summer Bird X1.4 16
p <- ggplot(dfm, aes(variable, value,
group = Horse, colour = Horse, label = Horse))
p1 <- p + geom_line(size=2) + geom_text(data = subset(dfm,variable == "Finish"), size=6,
aes(x = variable, hjust = -0.1))
labels <- c(expression(1/4), expression(1/2),
expression(3/4), "1m", "Str", "Finish",
"")
p1 + theme_bw() + theme(legend.position = "none", panel.border = element_blank(), axis.ticks = element_blank()) +
scale_x_discrete(breaks = c(levels(dfm$variable), ""), labels = labels) +
scale_y_continuous(breaks = NULL,trans = "reverse") + xlab(NULL) + ylab(NULL)+
theme(axis.text=element_text(size=21))
Tweaked by: Subasish Das