我想使用 mfrow
在一个图中组合多个图功能。
然后,我想将行数和列数添加到该图中。
例如,
par(mfrow=c(3,3))
plot(rnorm(10,1,3))
plot(rnorm(10,2,4))
plot(rnorm(10,3,3))
plot(rnorm(10,4,4))
plot(rnorm(10,5,2))
plot(rnorm(10,3,0.5))
我想有类似的:
请问有什么帮助吗?
最佳答案
我觉得你可以考虑GGally
包裹。它使用 ggplot2
绘制成对散点图.我想这就是你想要的。
library(tidyverse)
(mu_sd <- # parameters
tribble(
~m, ~s,
#--/--/
1, 3,
2, 4,
3, 3,
4, 4,
5, 2,
3, .5
))
#> # A tibble: 6 x 2
#> m s
#> <dbl> <dbl>
#> 1 1 3
#> 2 2 4
#> 3 3 3
#> 4 4 4
#> 5 5 2
#> 6 3 0.5
申请
rnorm
到这个数据框,我们可以得到另一个数据框来画图set.seed(10)
(rand_norm <-
mu_sd %>%
apply(1, rnorm, n = 10) %>% # to each row
as_tibble())
#> # A tibble: 10 x 6
#> V1 V2 V3 V4 V5 V6
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1.02 3.10 2.40 2.15 6.09 2.60
#> 2 2.82 4.76 0.815 3.92 1.24 0.165
#> 3 -0.371 1.76 2.33 4.97 4.17 4.37
#> 4 2.40 4.99 0.881 4.18 2.83 2.64
#> 5 1.29 2.74 1.73 2.62 4.03 3.51
#> 6 3.39 4.09 2.63 2.56 1.97 1.29
#> 7 -0.208 1.05 2.31 4.36 5.23 2.10
#> 8 2.64 3.80 2.13 2.24 1.70 1.03
#> 9 -0.627 2.93 2.90 3.68 4.32 2.35
#> 10 2.74 4.48 2.75 3.35 2.66 0.791
在这里,每一列都来自每个群体。
您现在可以使用
ggpairs()
在 GGally
.GGally::ggpairs(rand_norm)
您可以在每个
upper
中指定要绘制的内容, lower
, 和 diag
情节的一边。这是默认结果。在下半部分,您可能会看到您想要的结果。如果你对细节感兴趣,那么你可以去这个链接GGally .但是在这种情况下,我认为默认选项足以解决问题。
关于r - 如何将行数和列数添加到多个图中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53368453/