Reputation: 57
I have a dataset like this:
HR_1 HR_2 HR_3 HR_4 label
0.1 0.05 1.5 1.6 1
0.04 0.15 1.0 1.6 1
1.1 2.05 2.5 1.6 0
And I want to create parallel coordinates plot where my X axis is 1,2,3,4 and Y axis is my data. Moreover I want that the color for each line be same for all lines with the same label.
Right now I am using plotmd from EMcluster package that does what I want, but does not create a legend for the color behind the line, so I do not know to each class each color corresponds to.
Upvotes: 0
Views: 481
Reputation: 37641
You can add the legend with the legend
function. The hard part is finding what colors to use.
library(EMCluster)
plotmd(snapshots[,1:4],class = snapshots$label)
legend("bottomright", legend=unique(snapshots$label), lty=1,
col=color.class[unique(snapshots$label)%%length(color.class) + 1])
To find the colors, I typed plotmd
to look at the code for the plotmd function. You can see how the colors were created there. Notice that it colors the lines by the class - in your case, the label - so there is no distinction between rows 1 and 2.
Upvotes: 0
Reputation: 186
Use GGally:: ggparcoord()
library(GGally)
df$label <- as.factor(df$label) #label should be a factor
ggparcoord(df, columns = 1:4, groupColumn = 'label',
scale = 'globalminmax')
Upvotes: 1