Parallel Coordinates Plot With Skipped Coordinates
People are racing at 100 m, 400 m, 1600 m tracks and their finish time is recorded. I want to present data for each racer in parallel coordinates plot. Some racers may not finish t
Solution 1:
With R and ggplot2
:
Build some bogus data:
df <- data.frame(ID = factor(c(rep(1, 3), rep(2, 3), rep(3, 3)), labels = c('Realman', 'Lazyman', 'Superman')),
race = factor(rep(seq(1,3,1), 3), labels = c('100m', '400m', '1600m')),
runTime = c(8.9, 20.5, 150.9, 100.1, 300.3, +Inf, 1.2, 5, +Inf))
ID race runTime
# 1 Realman 100m 8.9# 2 Realman 400m 20.5# 3 Realman 1600m 150.9# 4 Lazyman 100m 100.1# 5 Lazyman 400m 300.3# 6 Lazyman 1600m Inf# 7 Superman 100m 1.2# 8 Superman 400m 5.0# 9 Superman 1600m Inf
Result:
Code:
ggplot(filter(df, runTime != +Inf), aes(x = race, y = runTime, group = ID, color = ID)) +
geom_line(size = 2) +
geom_point(size = 4) +
geom_line(data = df, linetype = 'dashed', size = 1) +
geom_point(data = df, shape = 21, size = 1) +
geom_text(aes(label = runTime), position = position_nudge(y = -.1)) +
scale_y_continuous(trans = 'log10', breaks = c(1, 10, 100, 1000)) +
scale_x_discrete('Track') +
scale_color_manual('Racer', values = brewer.pal(length(levels(df$ID)), 'Set1')) +
theme(panel.background = element_blank(),
panel.grid.major.x = element_line(colour = 'lightgrey', size = 25),
legend.position = 'top',
axis.line.y = element_line('black', .5, arrow = arrow()))
Post a Comment for "Parallel Coordinates Plot With Skipped Coordinates"