2017-09-14 2 views
4

以下はUpset plotです。私は、バーの色を定義するための色のパレットを使用しています。接続されたドットのマトリックスでもこれを行う方法はありますか?マトリックスにパレットを適用しようとするUpSetRのマトリックスポイントにカラーパレットを使用

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

、Iは赤、警告のみ第1の色を取得し、使用されています。

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

答えて

1

upsetmatrix.color 1つだけの色を指定することを可能にします。
溶液は、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

関連する問題