R中的复杂扰乱:按度数升序排序,在度数组内降序排序?

lxkprmvk  于 2023-06-19  发布在  其他
关注(0)|答案(2)|浏览(145)

遵循here概述的方法,下面的代码生成一个复杂的翻转图,其中条形图按度数组(例如,组合数)着色:

library(tidyverse)
library(ComplexUpset)

movies = as.data.frame(ggplot2movies::movies)
movies[movies$mpaa == '', 'mpaa'] = NA
movies = na.omit(movies)
genres = colnames(movies)[18:24]

query_by_degree = function(data, groups, params_by_degree, ...) {
  intersections = unique(upset_data(data, groups)$plot_intersections_subset)
  lapply(
    intersections,
    FUN=function(x) {
      members = ComplexUpset:::get_intersection_members(x)[[1]]
      degree = as.character(ComplexUpset:::calculate_degree(x))
      if (!(degree %in% names(params_by_degree))) {
        stop(
          paste('Missing specification of params for degree', degree)
        )
      }
      args = c(
        list(intersect=members, ...),
        params_by_degree[[degree]]
      )
      do.call(upset_query, args)
    }
  )
}

upset(
  movies,
  genres,
  width_ratio=0.1,
  sort_intersections="descending",
  sort_sets="ascending",
  sort_intersections_by=c('degree', 'cardinality'),
  queries=query_by_degree(
    movies, genres,
    params_by_degree=list(
      '1'=list(color='red', fill='red'),
      '2'=list(color='purple', fill='purple'),
      '3'=list(color='blue', fill='blue'),
      '4'=list(color='green', fill='green'),
      '0'=list(color='orange', fill='orange')
    ),
    only_components=c("intersections_matrix", "Intersection size")
  )
)

生产:

然而,似乎没有一种方法来首先按降序对彩色条进行排序,这意味着组从0到4,然后在这些降序组中进行排序,以制作如下所示的图:

如何实现这一目标有何建议?

u0njafvf

u0njafvf1#

sort_intersections = "ascending"

应该工作!

3htmauhk

3htmauhk2#

运行你的脚本,包括更正建议,我得到一个系统性错误消息:错误:!主题元素strip.clip未在元素层次结构中定义。运行rlang::last_error()查看错误发生的位置。你能解释一下吗

相关问题