pairs(data, lower.panel = function(x, y) { points(x, y, pch = 19, cex = 0.5, col = "#3C9668") abline(lm(y ~ x), col = "red") }, diag.panel = function(x) { hist(x,col = "#D8EAF6",probability = TRUE,axes = FALSE,main = "",breaks = "FD") }, upper.panel = function(x, y) { corr_text <- round(cor(x, y), 2) symbol_size <- abs(corr_text) * 5 color_scale <- colorRampPalette(c("#F09576","white","#175A9E")) # 颜色比例尺 symbol_color <- color_scale(5 + corr_text * 5) #symbol_color <- ifelse(corr_text >= 0, "#F09576","#175A9E") symbols(1, 1, circles = symbol_size, inches = FALSE, bg = symbol_color) }, labels = c("FBD", "VC", "EO","OF","DP","VC-FBD","EO-VC","OF-EO","DP-OF","DP-EO"), font.labels = list(cex = 1.5))出现Error in text.default(x, y, txt, cex = cex, font = font) : 字形设定不对的问题,怎么使右三角每个格子的圆和相关性数字在每个格子中心啊,求代码了,谢谢
时间: 2023-07-19 12:06:47 浏览: 90
这个问题可能是因为字形设定不正确导致的。你可以尝试在函数中添加一个`font`参数,指定字体类型,例如:
```
pairs(data, lower.panel = function(x, y) {
points(x, y, pch = 19, cex = 0.5, col = "#3C9668")
abline(lm(y ~ x), col = "red")
}, diag.panel = function(x) {
hist(x, col = "#D8EAF6", probability = TRUE, axes = FALSE, main = "", breaks = "FD")
}, upper.panel = function(x, y) {
corr_text <- round(cor(x, y), 2)
symbol_size <- abs(corr_text) * 5
color_scale <- colorRampPalette(c("#F09576", "white", "#175A9E"))
symbol_color <- color_scale(5 + corr_text * 5)
symbols(1, 1, circles = symbol_size, inches = FALSE, bg = symbol_color)
text(mean(x), mean(y), round(cor(x, y), 2), cex = 1.5, font = 2)
}, labels = c("FBD", "VC", "EO", "OF", "DP", "VC-FBD", "EO-VC", "OF-EO", "DP-OF", "DP-EO"), font.labels = list(cex = 1.5))
```
在`upper.panel`函数中添加了`text`函数,指定圆圈中心坐标和相关性数字,同时添加了`font`参数,指定字体类型为粗体(`font = 2`)。
阅读全文