0

I have this 4-variable Pareto front that I'd like to visualise. Here's the dataset: https://www.dropbox.com/s/3onja9wtsow4rl9/filtered_pareto.csv?dl=0

> head(dat)
       modu robust      apl     fiedl
1 0.3701243     35 2.151837 0.2932508
2 0.3067103     29 2.071020 0.2928233
3 0.3244840     26 2.124898 0.2646455
4 0.3396247     35 2.008980 0.3270429
5 0.2890496     29 2.010612 0.3110269
6 0.3528308     34 2.051429 0.3007537

And here's the code I use to plot all the combinations of variables:

library(ggplot2)

dat <- read.csv("filtered_pareto.csv", check.names = FALSE)

dat$modu = -dat$modu
dat$robust = -dat$robust

res <- do.call(rbind, combn(1:4, 2, function(ii)
    cbind(setNames(dat[,c(ii, setdiff(1:4, ii))], c("x", "y")),
                   var=paste(ii, collapse=".")), simplify=F))

ggplot(res, aes(x=x, y=y))+ geom_point(shape=4) + geom_smooth(method=lm) + 
  facet_wrap(~ var, scales="free")

After transformation, the data looks like this:

> head(res)
          x  y       NA        NA var
1 0.3701243 35 2.151837 0.2932508 1.2
2 0.3067103 29 2.071020 0.2928233 1.2
3 0.3244840 26 2.124898 0.2646455 1.2
4 0.3396247 35 2.008980 0.3270429 1.2
5 0.2890496 29 2.010612 0.3110269 1.2
6 0.3528308 34 2.051429 0.3007537 1.2

It produces this:

enter image description here

In this visualization, each plot is titled with two numbers, corresponding to the variables is displays. Is there a way to use the names of the variables instead (first row of the CSV dataset). in such format for instance: "Robust/Modu" instead of "1.2" or "APL/Modu" instead of "1.3", etc.?

Thanks!

Lucien S.
  • 5,123
  • 10
  • 52
  • 88
  • 1
    Change the values of your `var` variable in your `res` data frame to whatever you want the labels to be. – Gregor Thomas Aug 26 '15 at 23:23
  • How could I go about doing this? Should I try fiddling with lapply? – Lucien S. Aug 26 '15 at 23:26
  • Some people like `ifelse` statements, you could make a table and `merge` or `match`, you could just do a named vector. – Gregor Thomas Aug 26 '15 at 23:28
  • Possible dup of http://stackoverflow.com/questions/10151123/how-to-specify-columns-in-facet-grid-or-how-to-change-labels-in-facet-wrap but I don't want to do that officially unless confirmed. – hrbrmstr Aug 26 '15 at 23:33
  • 1
    I agree seems dupe-like, but from OP's comments the real problem here is *how* to add a column to this weirdly transformed data based on original data's names. I'm too short on time now to download the CSV and try to decode what the `do.call` with the `rbind` and the `setdiff` is doing. – Gregor Thomas Aug 26 '15 at 23:37
  • 1
    If OP posted the `head` of the data pre- and post-transformation, it might generate more interest. I know I'm not the only one reluctant to download random files. – Gregor Thomas Aug 26 '15 at 23:49

1 Answers1

1
res <- do.call(rbind, combn(1:4, 2, function(ii)
        cbind(setNames(dat[,c(ii, setdiff(1:4, ii))], c("x", "y")),
              var=paste(names(dat)[ii], collapse="/")), simplify=F))
HubertL
  • 19,246
  • 3
  • 32
  • 51