Plotly:平行坐标图:轴样式

时间:2018-01-24 11:47:40

标签: r plotly r-plotly

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

是否可以为某些坐标设置基于log10的轴?

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

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

我会很感激任何想法/指针。

plot

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

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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

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

enter image description here

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