6

我真的很喜欢 Plotly 中可用的平行坐标图,但我遇到了一个可以使用帮助的问题。

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

正如您在下面的示例中所见,执行 log10 变换可以更好地区分较小的值。但是,通过转换数据,我们失去了解释值的能力。我更愿意记录坐标轴而不是数据,但找不到这样做的方法。

我确实在 github 问题https://github.com/plotly/plotly.js/issues/1071#issuecomment-264860379中找到了与“轴样式”相关的内容,但不是解决此问题的方法。

我将不胜感激任何想法/指针。

阴谋

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

更多平行坐标示例

Plotly 平行坐标文档

4

2 回答 2

2

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

# 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
于 2018-01-26T14:04:34.913 回答
1

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

于 2018-01-25T12:22:21.733 回答