gpt4 book ai didi

r - 在 UpSetR 中为矩阵点使用调色板

转载 作者:行者123 更新时间:2023-12-04 09:33:54 32 4
gpt4 key购买 nike

下面我构建了一个 Upset plot .我正在使用调色板来定义条形颜色。对于连接点的矩阵,有没有办法做到这一点?

library(dplyr)
library(RColorBrewer)
library(UpSetR)

movies <- read.csv(system.file("extdata", "movies.csv",
package = "UpSetR"), header=T, sep=";" )
movies <- select(movies, Action:Children)

upset(movies, main.bar.color=brewer.pal(2^ncol(movies)-1, "Set1"))

enter image description here

尝试将调色板应用于矩阵时,我收到警告并且只使用第一种颜色红色。
upset(movies, main.bar.color=brewer.pal(2^ncol(movies)-1, "Set1"),
matrix.color=brewer.pal(2^ncol(movies)-1, "Set1"))

enter image description here

最佳答案

upset允许为 matrix.color 仅指定一种颜色.
解决办法是修改UpSetR:::Create_layout功能:

Create_layout <- function (setup, mat_color, mat_col, matrix_dot_alpha) 
{
Matrix_layout <- expand.grid(y = seq(nrow(setup)), x = seq(ncol(setup)))
Matrix_layout <- data.frame(Matrix_layout, value = as.vector(setup))
for (i in 1:nrow(Matrix_layout)) {
if (Matrix_layout$value[i] > as.integer(0)) {
# Here I propose to change Matrix_layout$color[i] <- mat_color with
# Matrix_layout$color[i] <- mat_color[i]
Matrix_layout$color[i] <- mat_color[i]
Matrix_layout$alpha[i] <- 1
Matrix_layout$Intersection[i] <- paste(Matrix_layout$x[i],
"yes", sep = "")
}
else {
Matrix_layout$color[i] <- "gray83"
Matrix_layout$alpha[i] <- matrix_dot_alpha
Matrix_layout$Intersection[i] <- paste(i, "No", sep = "")
}
}
if (is.null(mat_col) == F) {
for (i in 1:nrow(mat_col)) {
mat_x <- mat_col$x[i]
mat_color <- as.character(mat_col$color[i])
for (i in 1:nrow(Matrix_layout)) {
if ((Matrix_layout$x[i] == mat_x) && (Matrix_layout$value[i] !=
0)) {
Matrix_layout$color[i] <- mat_color
}
}
}
}
return(Matrix_layout)
}

# Replace Create_layout in UpSetR with the modified function
assignInNamespace(x="Create_layout", value=Create_layout, ns="UpSetR")

# Now you can set colors for the matrix of connected dots
# The dimension of this matrix is 3 x 7
upset(movies, main.bar.color=brewer.pal(2^ncol(movies)-1, "Set1"),
matrix.color=rainbow(21))

enter image description here

关于r - 在 UpSetR 中为矩阵点使用调色板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46223273/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com