带有跳过和未排序坐标的平行坐标图 [英] Parallel coordinates plot with skipped and unsorted coordinates

查看:172
本文介绍了带有跳过和未排序坐标的平行坐标图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

人们在不同的赛道上比赛,他们的时间是按照每个球场进行测量的。有些人可能无法完成一个曲目,并且他们的时间在数据框中用Inf标记。我想在平行坐标图中给出这些信息,并给出Inf值的特殊注释。

我想删除超人和拉齐曼穿过奥运会场地的线路。



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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆