Plotly:平行坐标图:轴样式

Plotly: Parallel Coordinates Plot: Axis Styling

我真的很喜欢中可用的平行坐标图 阴谋,但我只是 运行 遇到了一个我可以寻求帮助的问题。

某些坐标是否可以使用基于 log10 的轴?

正如您在下面的示例中看到的,执行 log10 t运行sform 可以更好地区分较小的值。然而,通过 t运行 形成数据,我们失去了解释这些值的能力。我更愿意对轴而不是数据进行日志缩放,但找不到执行此操作的方法。

我确实在 github 问题 https://github.com/plotly/plotly.js/issues/1071#issuecomment-264860379 中找到了与 "axis styling" 相关的内容,但是 不是这个问题的解决方案。

我将不胜感激 ideas/pointer。

library(plotly)

# Setting up some data that span a wide range.
df <- read.csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv")
df$sepal_width[1] = 50
df$sepal_width_log10 = log10(df$sepal_width)

p <- df %>%
plot_ly(type = 'parcoords',
        line = list(color = ~species_id,
                    colorscale = list(c(0,'red'),c(0.5,'green'),c(1,'blue'))),
        dimensions = list(
            list(range = c(~min(sepal_width),~max(sepal_width)),
                label = 'Sepal Width', values = ~sepal_width),
            list(range = c(~min(sepal_width_log10),~max(sepal_width_log10)),
                tickformat='.2f',
                label = 'log10(Sepal Width)', values = ~sepal_width_log10),
            list(range = c(4,8),
                constraintrange = c(5,6),
                label = 'Sepal Length', values = ~sepal_length))
        )
p

More Parallel Coordinate Examples

Plotly Parallel Coordinates Doc

底层 plotly.js parcoords 目前不支持对数投影(比例、轴),但正如您提到的,它有时会出现,我们计划使用此功能。同时,一个选项是提前对数据取对数,但最大的缺点是轴刻度会显示对数值,这需要解释并增加认知负担。

由于(尚)不支持对数投影,手动创建刻度标签似乎是一个有效的解决方案。

# Lets create the axis text manually and map the log10 transform
# back to the original scale.
my_tickvals = seq(min(df$sepal_width_log10), max(df$sepal_width_log10), length.out=8)
my_ticktext = signif(10 ^ my_tickvals, digits = 2)

library(plotly)

# Setting up some data that span a wide range.
df <- read.csv("https://raw.githubusercontent.com/bcdunbar/datasets/master/iris.csv")
df$sepal_width[1] = 50
df$sepal_width_log10 = log10(df$sepal_width)

# Lets create the axis text manually and map the log10 transform back to the original scale.
my_tickvals = seq(min(df$sepal_width_log10), max(df$sepal_width_log10), length.out=8)
my_ticktext = signif(10 ^ my_tickvals, digits = 2)

p <- df %>%
  plot_ly(type = 'parcoords',
          line = list(color = ~species_id,
                      colorscale = list(c(0,'red'),c(0.5,'green'),c(1,'blue'))),
          dimensions = list(
            list(range = c(~min(sepal_width),~max(sepal_width)),
                 label = 'Sepal Width', values = ~sepal_width),
            list(range = c(~min(sepal_width_log10),~max(sepal_width_log10)),
                 tickformat='.2f',
                 label = 'log10(Sepal Width)', values = ~sepal_width_log10),
            list(range = c(~min(sepal_width_log10),~max(sepal_width_log10)),
                 tickvals = my_tickvals,
                 ticktext = my_ticktext,
                 label = 'Sepal Width (log10 axis)', values = ~sepal_width_log10),
            list(range = c(4,8),
                 constraintrange = c(5,6),
                 label = 'Sepal Length', values = ~sepal_length))
          )
p