[英]How to change facetted plots' titles?
我有一個想看到的4變量帕累托曲線。 這是數據集: 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
這是我用來繪制變量的所有組合的代碼:
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")
轉換后,數據如下所示:
> 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
它產生此:
在此可視化中,每個圖用兩個數字作為標題,與顯示的變量相對應。 有沒有一種方法可以使用變量名稱代替(CSV數據集的第一行)。 例如:“ Robust / Modu”而不是“ 1.2”或“ APL / Modu”而不是“ 1.3”等?
謝謝!
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))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.