从列表列创建 ggplot/ggupset 时出错

问题描述

我正在尝试从列表列创建 ggplot。首先我创建列表列,然后创建 ggplot。预期的 ggplot 是一个 ggupset 来显示集合交集。我按照 ggupset 示例创建列表列和绘图。但是,当我尝试从列表列创建 geom_bar() 时收到以下警告:Warning message: Computation failed in stat_count():non-numeric argument to mathematical function。我也无法使用 tidy_pathway_member 重现 ggupset 示例。下面是一个简单的 reprex 以及 ggupset 示例。

感谢您的时间和帮助!

library(dplyr)
library(tidyr)
library(ggplot2)
library(ggupset)

# Simple reprex
df <-
  dplyr::tribble(
    ~id,~color,"a","red","b","blue","purple","c","d","blue"
  )

df_list_col <-
  df %>% 
  group_by(id) %>% 
  summarise(colors = list(color))
#> `summarise()` ungrouping output (override with `.groups` argument)

# ggplot fails
# desired output is a bar graph with each intersection of categories on x-axis (i.e.,"blue,purple","red,blue")
df_list_col %>% 
  ggplot(aes(x = colors)) +
  geom_bar() #+
#> Warning: Computation failed in `stat_count()`:
#> non-numeric argument to mathematical function

  # ggupset::scale_x_upset()

  # Reproduce example taken from `ggupset` (https://github.com/const-ae/ggupset)
tidy_pathway_member <- 
  ggupset::gene_pathway_membership %>%
  as_tibble(rownames = "Pathway") %>%
  tidyr::gather(Gene,Member,-Pathway) %>%
  filter(Member) %>%
  select(- Member)

tidy_pathway_member_list_col <-
  tidy_pathway_member %>% 
  group_by(Gene) %>%
  summarize(Pathways = list(Pathway)) 
#> `summarise()` ungrouping output (override with `.groups` argument)

# ggplot fails
# desired output available at https://github.com/const-ae/ggupset under "Reshaping quadratic data"
tidy_pathway_member_list_col %>% 
  ggplot(aes(x = Pathways)) +
  geom_bar() #+
#> Warning: Computation failed in `stat_count()`:
#> non-numeric argument to mathematical function

  # ggupset::scale_x_upset()

reprex package (v0.3.0) 于 2021 年 1 月 5 日创建

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)