我还添加了一个基本示例,以使此答案更具信息性。
解决方案之一是使用GGally::ggpairs 和plotly::ggplotly 函数。当然plotly::ggplotly返回的情节会是互动的。
# Base plot
panel.cor <- function(x, y) {
usr <- par("usr")
on.exit(par(usr))
par(usr = c(0, 1, 0, 1))
r <- round(cor(x, y), digits = 2)
# possible to edit the size
text(0.5, 0.5, r)
}
pairs(iris[, 1:4],
upper.panel = panel.cor
)
## GGally solution - plotly
## assume GGally and plotly are installed
pm <- GGally::ggpairs(iris[, 1:4])
#> Registered S3 method overwritten by 'GGally':
#> method from
#> +.gg ggplot2
class(pm)
#> [1] "gg" "ggmatrix"
plotly::ggplotly(pm)
由reprex package (v2.0.0) 于 2021-07-09 创建