簡體   English   中英

具有跳過坐標的平行坐標圖

[英]Parallel coordinates plot with skipped coordinates

人們以100 m,400 m,1600 m的速度進行比賽,並記錄他們的完成時間。 我想在平行坐標圖中顯示每個賽車手的數據。 一些賽車手可能無法完成比賽。 在這種情況下,我想以某種方式標記它,通過無窮遠點或某種方式用特定軌道的顏色標記。

舉例來說,我在畫圖中繪制了平行坐標圖: 在此處輸入圖片說明
Lazyman尚未完成1600m軌道,並標有x。

以下“ racing.csv”中給出了示例數據集:

RACER,TRACK.100m,TRACK.400m,TRACK.1500m
Superman,0.1,0.5,1
Lazyman,200,900,Inf

我已經嘗試過用熊貓解決方案:

import pandas
from pandas.tools.plotting import parallel_coordinates
import matplotlib.pyplot as plt

d = pandas.read_csv('racing.csv')

f = plt.figure()
parallel_coordinates(d, 'RACER')
f.axes[0].set_yscale('log')

plt.show()

這給出了在1600m處沒有Lazyman的Inf值的圖: 在此處輸入圖片說明

我還為ggplot准備了一個csv(也許有更好的方法可以做到這一點):

RACER,TRACK,TIME
Superman,100m,0.1
Superman,400m,0.5
Superman,1600m,1
Lazyman,100m,200
Lazyman,400m,900
Lazyman,1600m,Inf

使用ggplot:

require(ggplot2)
d <- read.csv('racing2.csv')
g <- ggplot(d) + geom_line(aes(x=TRACK,y=TIME,group=RACER, color=RACER))
g <- g + scale_y_log10()
ggsave('ggplot.png')

我走近了:

在此處輸入圖片說明
因為它顯示了一個無窮大值,但沒有對其做任何注釋。

任何解決方案,無論是Python還是R,都將受到贊賞。 此外,贊賞有關標記未完成的種族的建議。

使用R和ggplot2

建立一些假數據:

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

結果:

在此處輸入圖片說明

碼:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM