Reputation: 11
I am trying to create a parallel coordinates graph, but cannot seem to add colour to the lines. Any help appreciated.
I have tries various layers but have had no success. I just get back a chart with black lines.
a=c(min(customers[,1+1])-100,max(customers[,1+1])+100)
b=c(min(customers[,1+2])-100,max(customers[,1+2])+100)
c=c(min(customers[,1+3])-100,max(customers[,1+3])+100)
d=c(min(customers[,1+4])-100,max(customers[,1+4])+100)
p <- plot_ly(type = 'parcoords', line = list(color = c('red','blue','green','orange')),
dimensions = list(
list(range = a,
label = 'A', values = customers[,2]),
list(range = b,
label = 'B', values = customers[,3]),
list(range = c,
label = 'C', values = customers[,4]),
list(range = d,
label = 'D', values = customers[,5])
),colors=c('red','blue','green','orange')
)
p
Data is as follows:
Cust_Group Median_V10 Median_V5 Median_V1 Median_v0 Median_NetRev
1 Ctrl_Prem 163.370 357.420 3172.34 9769.17 131.2588
2 Treat_Prem 163.115 505.415 4013.02 10306.07 144.8187
3 Ctrl_Rec 169.880 366.770 3172.14 9769.17 134.7507
4 Treat_Rec 163.115 505.415 4013.02 10306.07 144.8187
Upvotes: 1
Views: 1906
Reputation: 27370
Unfortunately, parallel coordinates plots in Plotly do not currently support categorical colors. As a (somewhat-painful) workaround, you can encode your colors as numbers and then craft a colorscale that ensures that each number renders as the desired color. This example from our docs https://plot.ly/r/parallel-coordinates-plot/#basic-parallel-cordinates-plot shows how to do this. In this case species_id
is 1, 2 or 3 and the colorscale specifies 3 color values (mapped to 0, 0.5 and 1) which causes each species to render as the matching color.
Upvotes: 2