带有跳过和未排序坐标的平行坐标图 [英] Parallel coordinates plot with skipped and unsorted coordinates
问题描述
我想删除超人和拉齐曼穿过奥运会场地的线路。
FYI:Thi s是
People are racing on different tracks and their time is measured for each course. Some people may not finish a track and their time is marked with Inf in a data frame. I would like to present this information in a parallel coordinates plot with special annotation for Inf values.
The answer in a previous post had a code similar to this one:
require(ggplot2)
df <- data.frame(ID = factor(c(rep(1, 4), rep(2, 4), rep(3, 4)), labels = c('Realman', 'Lazyman', 'Superman')),
race = factor(rep(seq(1,4,1), 3), labels = c('Obstacle.Course', 'Olympic.Stadion', 'Jungle','Beach')),
runTime = c(8.9, 20.5, 150.9, 900, 100.1, +Inf, 300.3, 900, 1.2, +Inf, 5, 900))
str(df)
g <- 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()))
ggsave('image.png', g)
This produces an image with the following image:
I would like to remove the lines for Superman and Lazyman that cross the Olympic.Stadion.
FYI: This is a continuation on a previous question and there may be more information.
You can use NA values in the traces plotted on the solid lines, to break them where there are missing (infinite) values:
df$runTimeNA = df$runTime
df$runTimeNA[df$runTime==+Inf] = NA
ggplot(df, aes(x = race, y = runTime, group = ID, color = ID)) +
geom_line(aes(y = runTimeNA), 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()))
这篇关于带有跳过和未排序坐标的平行坐标图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!