我正在使用corrplot来显示相关性,但是标题在情节之上非常高,我想把它拉得更近.我该怎么做呢?
示例数据帧:
"VADeaths" <-
structure(c(11.7, 18.1, 26.9, 41, 66, 8.7, 11.7, 20.3, 30.9, 54.3, 15.4,
24.3, 37, 54.6, 71.1, 8.4, 13.6, 19.3, 35.1, 50), .Dim = c(5, 4),
.Dimnames = list(c("50-54", "55-59", "60-64", "65-69", "70-74"),
c("Rural Male", "Rural Female", "Urban Male", "Urban Female")))
Run Code Online (Sandbox Code Playgroud)
计算相关性并可视化
library(corrplot)
cors = cor(VADeaths)
corrplot(cors,tl.col="black",title="Example Plot",mar=c(0,0,5,0),tl.offset = 1)
Run Code Online (Sandbox Code Playgroud)
通过将边距扩展到图表上方的5,我至少可以使标题出现在图中,但无法弄清楚如何使标题更接近图并以图表为中心而不是标签占用的空间.
以上看起来像这样:
我想要更像这样的东西(忽略字体)
我的实际情节标签要小得多,因此标签与标题之间的间隙约为3-4厘米.我没有发现增加mar的价值解决了这个问题.
您可以使用mtext添加标题
corrplot(cors,tl.col="black", mar=c(0,0,5,0), tl.offset = 1)
mtext("Example Plot", at=2.5, line=-0.5, cex=2)
Run Code Online (Sandbox Code Playgroud)
at控制水平位置.line控制高度.cex为了大小.?mtext看到更多选择