简体   繁体   中英

How to change facetted plots' titles?

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:

在此处输入图片说明

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM