2017-03-02 20 views
0

人们在不同的轨道上进行比赛,他们的时间是针对每个球场进行测量的。有些人可能无法完成一个曲目,并且他们的时间在数据框中用Inf标记。我想将这些信息显示在平行坐标图中,并为Inf值提供特殊注释。具有跳过和未排序坐标的平行坐标绘图

previous post答案有类似这样的代码:

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) 

这与下面的图像产生图像: enter image description here
我想删除跨超人和Lazyman线奥运。体育场馆。

仅供参考:此为previous question的延续,可能有更多信息。

回答

1

您可以绘制在实线的痕迹使用NA值,打破他们那里有缺失(无限)值:

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())) 

enter image description here