循环 ggscatter 函数,用于数据框列中 x、y 变量的唯一组合
looping ggscatter function for unique combinations of x,y variables from dataframe columns
我需要绘制散点图来评估线性回归。我想使用 "ggscatter" 函数,但我需要编写循环。
我在这个平台和其他网站上查了很多例子,但我找不到合适的解决方案。
数据需要作为对应于单独列的 x,y 变量的 45 个唯一组合引入。因此将有 45 个地块,这些地块可以绘制为具有 4 列和 4 行的多地块图中的子地块。因此,输出将是 3 个图形文件。
例如,唯一的 x,y 组合是 A,B; A、C;广告; ... B,C; B,D;是; ... 你好; H,J;还有我,J.
x 和 y 成对变化,而不是其中一个是常数。
数据帧的维度是 ncol=10,nrow=28
A B C D E F G H I J
0.99 0.13 0.88 0.07 7.83 3.63 6.78 14.5 76.7 880.3
0.29 0.84 0.75 0.93 2.69 7.71 8.23 84.7 12.9 476.8
0.54 0.22 0.99 0.60 8.57 8.53 4.56 79.1 21.3 686.9
0.84 0.89 0.82 0.50 0.48 8.40 2.96 24.5 35.5 300.1
0.58 0.98 0.86 0.41 3.05 6.48 2.36 75.5 43.5 993.4
0.21 0.78 0.64 0.90 3.32 3.03 0.02 89.2 18.1 358.0
0.07 0.46 0.66 0.42 2.97 9.35 0.42 68.2 59.2 576.5
0.19 0.01 0.89 0.69 6.59 6.93 4.23 46.6 74.1 299.7
0.33 0.05 0.60 0.58 9.86 1.37 5.20 79.2 28.9 494.1
0.25 0.50 0.01 0.29 7.64 6.23 4.80 48.4 96.5 762.2
0.30 0.96 0.71 0.85 6.89 5.08 0.48 50.3 80.8 396.7
0.03 0.18 0.25 0.56 0.57 3.83 7.91 58.5 43.6 201.7
0.59 0.62 0.74 0.62 0.59 0.00 2.62 63.3 51.6 416.0
0.53 0.18 0.21 0.96 9.68 1.80 1.71 69.5 28.4 584.1
0.25 0.05 0.46 0.92 9.16 2.64 8.15 24.5 80.7 699.0
0.33 0.88 0.99 0.70 1.60 5.38 0.26 64.4 60.0 265.3
0.06 0.57 0.75 0.69 5.55 0.02 0.77 47.5 82.4 729.1
0.90 0.55 0.26 0.26 1.38 6.24 0.31 28.4 61.5 181.5
0.77 0.74 0.42 0.94 3.35 7.75 3.46 22.2 78.5 347.8
0.61 0.16 0.98 0.51 8.81 8.27 3.86 42.4 67.8 303.1
0.26 0.58 0.71 0.24 1.97 9.14 5.67 65.6 63.9 967.4
0.16 0.35 0.26 0.23 4.25 3.98 9.07 99.2 83.6 817.9
0.71 0.87 0.31 0.94 0.55 5.72 0.15 86.3 41.8 579.1
0.23 0.45 0.19 0.45 0.10 0.52 5.53 46.8 47.7 788.5
0.57 0.82 0.68 0.55 2.23 6.83 4.93 67.2 94.4 482.7
0.93 0.26 0.89 0.48 6.85 3.95 6.82 76.2 88.9 551.9
0.70 0.72 0.02 0.99 1.07 0.62 8.03 19.4 88.9 355.9
0.06 0.24 0.46 0.74 5.18 1.15 8.69 18.4 100.0 676.7
R脚本如下:
setwd("working_directory")
data <- read.table("data.txt", header=TRUE)
attach(data)
str(data)
### It was possible to draw histograms as below
### Multiple histogram plot (uses single x variable with plot function)
library(rcompanion)
histplot <- function (df) {
plots <- vector('list', ncol(df))
for (i in seq_along(df)) {
plots[[i]] <- local({
i <- i
p1 <- plotNormalHistogram(df[[i]],
prob=FALSE,
main=paste("Histogram of",colnames(df[i]),"\n with Std.Norm. Curve"))
})
}
}
dev.new()
par(mfrow=c(3,4))
histplot(data)
### Multiple scatterplot (uses two variable (x,y) with plot function)
### There are 45 unique combinations for 10 different data columns and I need to write a loop for this plot, but I couldn't write it
library(ggplot2)
library(ggpubr)
### multiplot function for defining subplot layouts with ggplot functions
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
require(grid)
plots <- c(list(...), plotlist)
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
for (i in 1:numPlots) {
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
### scatterplot function (I need a loop after here but I couldn't write it)
dev.new()
p1 <- ggscatter(data, x="A",y="B", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="B")
p2 <- ggscatter(data, x="A",y="C", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="C")
p3 <- ggscatter(data, x="A",y="D", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="D")
p4 <- ggscatter(data, x="A",y="E", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="E")
p5 <- ggscatter(data, x="A",y="F", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="F")
p6 <- ggscatter(data, x="A",y="G", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="G")
p7 <- ggscatter(data, x="A",y="H", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="H")
p8 <- ggscatter(data, x="A",y="I", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="I")
p9 <- ggscatter(data, x="A",y="J", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="J")
p10 <- ggscatter(data, x="B",y="C", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="C")
p11 <- ggscatter(data, x="B",y="D", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="D")
p12 <- ggscatter(data, x="B",y="E", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="E")
p13 <- ggscatter(data, x="B",y="F", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="F")
p14 <- ggscatter(data, x="B",y="G", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="G")
p15 <- ggscatter(data, x="B",y="H", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="H")
p16 <- ggscatter(data, x="B",y="I", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="I")
multiplot(plotlist = list(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16), cols = 4)
dev.new()
p17 <- ...
.
.
p32 <- ...
multiplot(...)
dev.new()
p33 <- ...
.
.
p45 <- ...
multiplot(...)
您可以尝试这样的操作(我使用 cowplot
中的 plot_grid
而不是 multiplot
来缩短可重现的示例)
library(ggplot2)
library(ggpubr)
#> Loading required package: magrittr
library(cowplot)
#>
#> ********************************************************
#> Note: As of version 1.0.0, cowplot does not change the
#> default ggplot2 theme anymore. To recover the previous
#> behavior, execute:
#> theme_set(theme_cowplot())
#> ********************************************************
#>
#> Attaching package: 'cowplot'
#> The following object is masked from 'package:ggpubr':
#>
#> get_legend
data <- structure(list(A = c(0.99, 0.29, 0.54, 0.84, 0.58, 0.21, 0.07, 0.19, 0.33, 0.25, 0.3, 0.03, 0.59, 0.53, 0.25, 0.33, 0.06, 0.9, 0.77, 0.61, 0.26, 0.16, 0.71, 0.23, 0.57, 0.93, 0.7, 0.06), B = c(0.13, 0.84, 0.22, 0.89, 0.98, 0.78, 0.46, 0.01, 0.05, 0.5, 0.96, 0.18, 0.62, 0.18, 0.05, 0.88, 0.57, 0.55, 0.74, 0.16, 0.58, 0.35, 0.87, 0.45, 0.82, 0.26, 0.72, 0.24), C = c(0.88, 0.75, 0.99, 0.82, 0.86, 0.64, 0.66, 0.89, 0.6, 0.01, 0.71, 0.25, 0.74, 0.21, 0.46, 0.99, 0.75, 0.26, 0.42, 0.98, 0.71, 0.26, 0.31, 0.19, 0.68, 0.89, 0.02, 0.46), D = c(0.07, 0.93, 0.6, 0.5, 0.41, 0.9, 0.42, 0.69, 0.58, 0.29, 0.85, 0.56, 0.62, 0.96, 0.92, 0.7, 0.69, 0.26, 0.94,0.51, 0.24, 0.23, 0.94, 0.45, 0.55, 0.48, 0.99, 0.74), E = c(7.83, 2.69, 8.57, 0.48, 3.05, 3.32, 2.97, 6.59, 9.86, 7.64, 6.89, 0.57, 0.59, 9.68, 9.16, 1.6, 5.55, 1.38, 3.35, 8.81, 1.97, 4.25, 0.55, 0.1, 2.23, 6.85, 1.07, 5.18), F = c(3.63, 7.71, 8.53, 8.4, 6.48, 3.03, 9.35, 6.93, 1.37, 6.23, 5.08, 3.83, 0, 1.8, 2.64, 5.38, 0.02, 6.24, 7.75, 8.27, 9.14, 3.98, 5.72, 0.52, 6.83, 3.95, 0.62, 1.15), G = c(6.78, 8.23, 4.56, 2.96, 2.36, 0.02, 0.42, 4.23, 5.2, 4.8, 0.48, 7.91, 2.62, 1.71, 8.15, 0.26, 0.77, 0.31, 3.46, 3.86, 5.67, 9.07, 0.15, 5.53, 4.93, 6.82, 8.03, 8.69), H = c(14.5, 84.7, 79.1, 24.5, 75.5, 89.2, 68.2, 46.6, 79.2, 48.4, 50.3, 58.5, 63.3, 69.5, 24.5, 64.4, 47.5, 28.4, 22.2, 42.4, 65.6, 99.2, 86.3, 46.8, 67.2, 76.2, 19.4, 18.4), I = c(76.7, 12.9, 21.3, 35.5, 43.5, 18.1, 59.2, 74.1, 28.9, 96.5, 80.8, 43.6, 51.6, 28.4, 80.7, 60, 82.4, 61.5, 78.5, 67.8, 63.9, 83.6, 41.8, 47.7, 94.4, 88.9, 88.9, 100), J = c(880.3, 476.8, 686.9, 300.1, 993.4, 358, 576.5, 299.7, 494.1, 762.2, 396.7, 201.7, 416, 584.1, 699, 265.3, 729.1, 181.5, 347.8, 303.1, 967.4, 817.9, 579.1, 788.5, 482.7, 551.9, 355.9, 676.7)), class = "data.frame", row.names = c(NA, -28L))
plotComb <- combn(colnames(data), 2, simplify = FALSE)
scatterfn <- function(l, data=data){
ggscatter(data, x=l[1], y=l[2], add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab=l[1], ylab=l[2])
}
plots <- lapply(plotComb, scatterfn, data=data)
plots <- split(plots, ceiling(seq_along(plots)/16))
pdf(file="Rplot1.pdf", width=12, height=12)
lapply(plots, function(x) plot_grid(plotlist=x, cols=4))
dev.off()
由 reprex package (v0.3.0)
于 2020-04-18 创建
我需要绘制散点图来评估线性回归。我想使用 "ggscatter" 函数,但我需要编写循环。
我在这个平台和其他网站上查了很多例子,但我找不到合适的解决方案。
数据需要作为对应于单独列的 x,y 变量的 45 个唯一组合引入。因此将有 45 个地块,这些地块可以绘制为具有 4 列和 4 行的多地块图中的子地块。因此,输出将是 3 个图形文件。
例如,唯一的 x,y 组合是 A,B; A、C;广告; ... B,C; B,D;是; ... 你好; H,J;还有我,J.
x 和 y 成对变化,而不是其中一个是常数。
数据帧的维度是 ncol=10,nrow=28
A B C D E F G H I J
0.99 0.13 0.88 0.07 7.83 3.63 6.78 14.5 76.7 880.3
0.29 0.84 0.75 0.93 2.69 7.71 8.23 84.7 12.9 476.8
0.54 0.22 0.99 0.60 8.57 8.53 4.56 79.1 21.3 686.9
0.84 0.89 0.82 0.50 0.48 8.40 2.96 24.5 35.5 300.1
0.58 0.98 0.86 0.41 3.05 6.48 2.36 75.5 43.5 993.4
0.21 0.78 0.64 0.90 3.32 3.03 0.02 89.2 18.1 358.0
0.07 0.46 0.66 0.42 2.97 9.35 0.42 68.2 59.2 576.5
0.19 0.01 0.89 0.69 6.59 6.93 4.23 46.6 74.1 299.7
0.33 0.05 0.60 0.58 9.86 1.37 5.20 79.2 28.9 494.1
0.25 0.50 0.01 0.29 7.64 6.23 4.80 48.4 96.5 762.2
0.30 0.96 0.71 0.85 6.89 5.08 0.48 50.3 80.8 396.7
0.03 0.18 0.25 0.56 0.57 3.83 7.91 58.5 43.6 201.7
0.59 0.62 0.74 0.62 0.59 0.00 2.62 63.3 51.6 416.0
0.53 0.18 0.21 0.96 9.68 1.80 1.71 69.5 28.4 584.1
0.25 0.05 0.46 0.92 9.16 2.64 8.15 24.5 80.7 699.0
0.33 0.88 0.99 0.70 1.60 5.38 0.26 64.4 60.0 265.3
0.06 0.57 0.75 0.69 5.55 0.02 0.77 47.5 82.4 729.1
0.90 0.55 0.26 0.26 1.38 6.24 0.31 28.4 61.5 181.5
0.77 0.74 0.42 0.94 3.35 7.75 3.46 22.2 78.5 347.8
0.61 0.16 0.98 0.51 8.81 8.27 3.86 42.4 67.8 303.1
0.26 0.58 0.71 0.24 1.97 9.14 5.67 65.6 63.9 967.4
0.16 0.35 0.26 0.23 4.25 3.98 9.07 99.2 83.6 817.9
0.71 0.87 0.31 0.94 0.55 5.72 0.15 86.3 41.8 579.1
0.23 0.45 0.19 0.45 0.10 0.52 5.53 46.8 47.7 788.5
0.57 0.82 0.68 0.55 2.23 6.83 4.93 67.2 94.4 482.7
0.93 0.26 0.89 0.48 6.85 3.95 6.82 76.2 88.9 551.9
0.70 0.72 0.02 0.99 1.07 0.62 8.03 19.4 88.9 355.9
0.06 0.24 0.46 0.74 5.18 1.15 8.69 18.4 100.0 676.7
R脚本如下:
setwd("working_directory")
data <- read.table("data.txt", header=TRUE)
attach(data)
str(data)
### It was possible to draw histograms as below
### Multiple histogram plot (uses single x variable with plot function)
library(rcompanion)
histplot <- function (df) {
plots <- vector('list', ncol(df))
for (i in seq_along(df)) {
plots[[i]] <- local({
i <- i
p1 <- plotNormalHistogram(df[[i]],
prob=FALSE,
main=paste("Histogram of",colnames(df[i]),"\n with Std.Norm. Curve"))
})
}
}
dev.new()
par(mfrow=c(3,4))
histplot(data)
### Multiple scatterplot (uses two variable (x,y) with plot function)
### There are 45 unique combinations for 10 different data columns and I need to write a loop for this plot, but I couldn't write it
library(ggplot2)
library(ggpubr)
### multiplot function for defining subplot layouts with ggplot functions
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
require(grid)
plots <- c(list(...), plotlist)
numPlots = length(plots)
if (is.null(layout)) {
layout <- matrix(seq(1, cols * ceiling(numPlots/cols)),
ncol = cols, nrow = ceiling(numPlots/cols))
}
if (numPlots==1) {
print(plots[[1]])
} else {
grid.newpage()
pushViewport(viewport(layout = grid.layout(nrow(layout), ncol(layout))))
for (i in 1:numPlots) {
matchidx <- as.data.frame(which(layout == i, arr.ind = TRUE))
print(plots[[i]], vp = viewport(layout.pos.row = matchidx$row,
layout.pos.col = matchidx$col))
}
}
}
### scatterplot function (I need a loop after here but I couldn't write it)
dev.new()
p1 <- ggscatter(data, x="A",y="B", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="B")
p2 <- ggscatter(data, x="A",y="C", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="C")
p3 <- ggscatter(data, x="A",y="D", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="D")
p4 <- ggscatter(data, x="A",y="E", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="E")
p5 <- ggscatter(data, x="A",y="F", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="F")
p6 <- ggscatter(data, x="A",y="G", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="G")
p7 <- ggscatter(data, x="A",y="H", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="H")
p8 <- ggscatter(data, x="A",y="I", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="I")
p9 <- ggscatter(data, x="A",y="J", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="A", ylab="J")
p10 <- ggscatter(data, x="B",y="C", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="C")
p11 <- ggscatter(data, x="B",y="D", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="D")
p12 <- ggscatter(data, x="B",y="E", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="E")
p13 <- ggscatter(data, x="B",y="F", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="F")
p14 <- ggscatter(data, x="B",y="G", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="G")
p15 <- ggscatter(data, x="B",y="H", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="H")
p16 <- ggscatter(data, x="B",y="I", add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab="B", ylab="I")
multiplot(plotlist = list(p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16), cols = 4)
dev.new()
p17 <- ...
.
.
p32 <- ...
multiplot(...)
dev.new()
p33 <- ...
.
.
p45 <- ...
multiplot(...)
您可以尝试这样的操作(我使用 cowplot
中的 plot_grid
而不是 multiplot
来缩短可重现的示例)
library(ggplot2)
library(ggpubr)
#> Loading required package: magrittr
library(cowplot)
#>
#> ********************************************************
#> Note: As of version 1.0.0, cowplot does not change the
#> default ggplot2 theme anymore. To recover the previous
#> behavior, execute:
#> theme_set(theme_cowplot())
#> ********************************************************
#>
#> Attaching package: 'cowplot'
#> The following object is masked from 'package:ggpubr':
#>
#> get_legend
data <- structure(list(A = c(0.99, 0.29, 0.54, 0.84, 0.58, 0.21, 0.07, 0.19, 0.33, 0.25, 0.3, 0.03, 0.59, 0.53, 0.25, 0.33, 0.06, 0.9, 0.77, 0.61, 0.26, 0.16, 0.71, 0.23, 0.57, 0.93, 0.7, 0.06), B = c(0.13, 0.84, 0.22, 0.89, 0.98, 0.78, 0.46, 0.01, 0.05, 0.5, 0.96, 0.18, 0.62, 0.18, 0.05, 0.88, 0.57, 0.55, 0.74, 0.16, 0.58, 0.35, 0.87, 0.45, 0.82, 0.26, 0.72, 0.24), C = c(0.88, 0.75, 0.99, 0.82, 0.86, 0.64, 0.66, 0.89, 0.6, 0.01, 0.71, 0.25, 0.74, 0.21, 0.46, 0.99, 0.75, 0.26, 0.42, 0.98, 0.71, 0.26, 0.31, 0.19, 0.68, 0.89, 0.02, 0.46), D = c(0.07, 0.93, 0.6, 0.5, 0.41, 0.9, 0.42, 0.69, 0.58, 0.29, 0.85, 0.56, 0.62, 0.96, 0.92, 0.7, 0.69, 0.26, 0.94,0.51, 0.24, 0.23, 0.94, 0.45, 0.55, 0.48, 0.99, 0.74), E = c(7.83, 2.69, 8.57, 0.48, 3.05, 3.32, 2.97, 6.59, 9.86, 7.64, 6.89, 0.57, 0.59, 9.68, 9.16, 1.6, 5.55, 1.38, 3.35, 8.81, 1.97, 4.25, 0.55, 0.1, 2.23, 6.85, 1.07, 5.18), F = c(3.63, 7.71, 8.53, 8.4, 6.48, 3.03, 9.35, 6.93, 1.37, 6.23, 5.08, 3.83, 0, 1.8, 2.64, 5.38, 0.02, 6.24, 7.75, 8.27, 9.14, 3.98, 5.72, 0.52, 6.83, 3.95, 0.62, 1.15), G = c(6.78, 8.23, 4.56, 2.96, 2.36, 0.02, 0.42, 4.23, 5.2, 4.8, 0.48, 7.91, 2.62, 1.71, 8.15, 0.26, 0.77, 0.31, 3.46, 3.86, 5.67, 9.07, 0.15, 5.53, 4.93, 6.82, 8.03, 8.69), H = c(14.5, 84.7, 79.1, 24.5, 75.5, 89.2, 68.2, 46.6, 79.2, 48.4, 50.3, 58.5, 63.3, 69.5, 24.5, 64.4, 47.5, 28.4, 22.2, 42.4, 65.6, 99.2, 86.3, 46.8, 67.2, 76.2, 19.4, 18.4), I = c(76.7, 12.9, 21.3, 35.5, 43.5, 18.1, 59.2, 74.1, 28.9, 96.5, 80.8, 43.6, 51.6, 28.4, 80.7, 60, 82.4, 61.5, 78.5, 67.8, 63.9, 83.6, 41.8, 47.7, 94.4, 88.9, 88.9, 100), J = c(880.3, 476.8, 686.9, 300.1, 993.4, 358, 576.5, 299.7, 494.1, 762.2, 396.7, 201.7, 416, 584.1, 699, 265.3, 729.1, 181.5, 347.8, 303.1, 967.4, 817.9, 579.1, 788.5, 482.7, 551.9, 355.9, 676.7)), class = "data.frame", row.names = c(NA, -28L))
plotComb <- combn(colnames(data), 2, simplify = FALSE)
scatterfn <- function(l, data=data){
ggscatter(data, x=l[1], y=l[2], add="reg.line", conf.int=TRUE, cor.coef=TRUE, cor.method="pearson", xlab=l[1], ylab=l[2])
}
plots <- lapply(plotComb, scatterfn, data=data)
plots <- split(plots, ceiling(seq_along(plots)/16))
pdf(file="Rplot1.pdf", width=12, height=12)
lapply(plots, function(x) plot_grid(plotlist=x, cols=4))
dev.off()
由 reprex package (v0.3.0)
于 2020-04-18 创建