14

I want to implement parallel coordinates for my muldimensional result. Does anyone have a good link to its implementation in matlab or R? Furthermore, are there any suggestions regarding the best tool to use for producing the parallel coordinates?

MattBagg
  • 10,268
  • 3
  • 40
  • 47
discipulus
  • 2,665
  • 3
  • 34
  • 51
  • 5
    No idea why this was closed, it seems reasonable to me. ggplot2 has a helper function, [`ggpcp()`](http://docs.ggplot2.org/0.9.3/ggpcp.html) that allows you to use any data frame with the standard geoms to create a parallel coordinates plot. – naught101 Mar 13 '14 at 00:20
  • You can now make interactive parallel coordinates with Plotly. Check it out: https://plot.ly/r/parallel-coordinates-plot/ – bcd Apr 11 '17 at 11:36

4 Answers4

21

R solution

lattice package comes with R and includes parallel function:

 parallel(~iris[1:4] | Species, iris) 

alt text

ggplot2 is also your friend here:

D <- data.frame(Gain = rnorm(20),  
                Trader = factor(LETTERS[1:4]), 
                Day = factor(rep(1:5, each = 4)))
ggplot(D) + 
  geom_line(aes(x = Trader, y = Gain, group = Day, color = Day))

alt text

lattice and ggplot require input data in different "shapes". For lattice it's a matrix form, each column is a variable represented on one parallel coordinate. For ggplot it's one column (Gains) and a separate indicator for the variable (Trader above). /this is the reason I used two different examples, not to mess with data reshaping here/.

If you need something quick, then lattice is probably for you. Ggplot requires some time investment.

Community
  • 1
  • 1
VitoshKa
  • 8,387
  • 3
  • 35
  • 59
  • 1
    For ggplot2 solution - there is also [ggparcoord](http://www.inside-r.org/packages/cran/GGally/docs/ggparcoord) function in the [GGally](http://cran.r-project.org/web/packages/GGally/) package. – radek Apr 12 '13 at 12:02
  • I was trying out using ggplot, it works fine for 20 items. But if I generate 40 items then each day gets 8 points(e.g. there is a vertical line in A for day1 as there are 2 points). Could you please tell me a way to split the line for every four points. – Prashanth Palaniswamy Oct 18 '17 at 23:15
6

If you are looking to use parallel coordinates, MATLAB has an implementation in the Statistics Toolbox: PARALLELCOORDS.

Otherwise if you want to implement one yourself, the basic version (without all of the bells and whistles) should be easy to do:

load fisheriris            %# load some data
%#meas = zscore(meas);     %# to normalize the attributes
h = plot(meas');            %'# plot
set(gca, 'XTick',1:4, 'XTickLabel',{'SL' 'SW' 'PL' 'PW'}, 'XGrid','on')
ylabel('feature value'), title('Parallel Coordinates')

%# color according to class label
c = grp2idx(species);
clr = lines( numel(c) );
arrayfun(@(k) set(h(c==k),'Color',clr(k,:)), unique(c))

alt text

Amro
  • 123,847
  • 25
  • 243
  • 454
  • @downvoter: Care to explain your down-vote? OP asked for either R or MATLAB code; the above code works just fine.. – Amro Mar 04 '13 at 00:18
  • Sorry, I downvoted because I didn't notice the question also asked for MATLAB... I feel bad and have tried to remove my downvote but its locked in. – Clayton Mar 08 '13 at 08:49
6

GGobi has had for aeons (as its predecessor XGobi already had it).

You can access this via the rggobi package from R. And being open source, you get to look under the hood too.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
4

The MASS package (available to most of the R installations) includes an implementation for parallel coordinates. The function parcoord.

From the examples of the ?parcoord -a bit corrected- for the Iris data set:

ir <- rbind(iris3[,,1], iris3[,,2], iris3[,,3])
parcoord(log(ir)[, c(1, 2, 3, 4)], col = 1 + (0:149)%/%50)
Knak
  • 496
  • 3
  • 14
Costas B.
  • 186
  • 12