R语言ggpairs:修改相关矩阵中分类箱线图的点为蓝色的方法
相关矩阵可视化工具:箱线图点颜色修改问题
我正在开发一款基于R语言的相关矩阵可视化工具,目标是让整个图表显示为蓝色,且适配任意数据集的列。目前已实现矩阵中部分图表的颜色设置,但轴上方分类变量对应的箱线图中的点无法改为蓝色。此外,受可用库限制,无法使用gginnards(Power BI仅支持官方列出的R包)。
当前可视化效果:
当前代码:
ERRORCHECK = FALSE options(warn=0) library(ggplot2); library(GGally); for (i in colnames(Values)){ Values[[i]] <- unlist(Values[[i]]) } p <- ggpairs(Values, mapping = ggplot2::aes(fill = "cornflowerblue", alpha = .5)) for(i in 1:p$nrow) { for(j in 1:p$ncol){ p[i,j] <- p[i,j] + scale_fill_manual(values="cornflowerblue") } } f <- sapply(Values, is.factor) middle <- p$ncol/2 middleround <- ceiling(middle) even <- FALSE if (middle == middleround) { even <- TRUE } whereami <- function(i, j, ifprint) { #TESTING WHERE WE ARE IN THE GRAPH axis = FALSE TOP = FALSE BOTTOM = FALSE if (even==TRUE) { if (i==j){ axis = TRUE } else if (j>i) { TOP = TRUE } else if (i>j) { BOTTOM = TRUE } else { #ERROR print("You shoulnd't see this. EVEN = TRUE") } } else if (even==FALSE) { if (i==j){ axis = TRUE } else if (j>i) { TOP = TRUE } else if (i>j) { BOTTOM = TRUE } else { #ERROR print("You shoulnd't see this. EVEN = FALSE") } } else { print("You shuound't see this. Even is neither TRUE not FALSE") } if (ifprint == TRUE){ print("----") print("axis") print(axis) print("top") print(TOP) print("bottom") print(BOTTOM) print("row") print(i) print("column") print(j) rowname <- colnames(Values)[i] colname <- colnames(Values)[j] print("rowname") print(rowname) print("colname") print(colname) } returnlist <- list("bottom" = BOTTOM, "top" = TOP, "axis" = axis) return(returnlist) } for(i in 1:p$nrow) { for(j in 1:p$ncol){ wheream <- whereami(i,j, FALSE) BOTTOM <- wheream$bottom TOP <- wheream$top axis <- wheream$axis if (i==j) { #AXIS # DO NOTHING } else if (!(f[i])&!(f[j])) { #BOTH CONTINUOUS # ABOVE AXIS, NO CHANGE. BELOW AXIS, ADD GEOM POINT AND COLOUR MANUAL if (BOTTOM == TRUE) { p[i,j] <- p[i,j] + geom_point(aes(colour = "cornflowerblue")) + scale_colour_manual(values = "cornflowerblue") } else if (TOP == TRUE) { # DO NOTHING } else { print("You shouldn't see this. Both are continuous, neither bottom nor top is true") } } else if ((!(f[i])&(f[j]))) { #ROW CONTINUOUS, COLUMN DISCRETE if (BOTTOM == TRUE) { # DO NOTHING } else if (TOP == TRUE) { # Discrete-continuous top. Still working on this. } else { print("You shouldn't see this. Row is continuous, column discrete, neither bottom nor top is true") } } else if ((f[i])&!(f[j])) { #ROW DISCRETE, COLUMN CONTINUOUS if (BOTTOM == TRUE) { # DO NOTHING } else if (TOP == TRUE) { # Discrete-continuous top. Still working on this. } else { print("You shouldn't see this. Row is discrete, column continuous, neither bottom nor top is true") } } else if ((f[i])&(f[j])) { #BOTH DISCRETE if (BOTTOM == TRUE) { # DO NOTHING } else if (TOP == TRUE) { # DO NOTHING } else { print("You shouldn't see this. Both discrete, neither bottom nor top is true") } } else { #ERROR HANDLING print("You shouln't see this message. ") } } } errorchecker <- function(nothing){ #ERROR CHECKER print("BEGINNING ERROR CHECKING") for(i in 1:p$nrow) { for(j in 1:p$ncol){ tryCatch( expr = { print(p[i,j]) }, error = function(e){ print("ERROR AT:") wheream <- whereami(i,j, TRUE) } ) } } print("DONE ERROR CHECKING") } if (ERRORCHECK == TRUE){ errorchecker() } p
恳请提供修改这些箱线图中点颜色为蓝色的解决方案。
内容的提问来源于stack exchange,提问作者Lukas Taylor
相关产品推荐
相关产品推荐

