1

我有一个看起来像这样的数据框,

  df <- data.frame(type=c("SNP","DEL","SNP","SNP"),geneA=c(1,1,1,0), geneB=c(0,0,1,1), geneC=c(1,0,0,1))

   type geneA geneB geneC
1  SNP     1     0     1
2  DEL     1     0     0
3  SNP     1     1     0
4  SNP     0     1     1

我想在 R 中制作一个 UpSet 图以查找常见基因,并且
我想在直方图中绘制类型(SNP 或 DEL)的分布。

这是我到目前为止的代码

  upset(df, 
        attribute.plots = list(gridrows=50,
                           plots=list(list(plot=histogram,
                                           x="type"))))

这是我的错误,我无法解决

Error: StatBin requires a continuous x variable: the x variable is discrete.Perhaps you want stat="count"?

在此处输入图像描述

非常感谢任何帮助

4

1 回答 1

1

我不确定究竟是什么the distribution of types (SNP or DEL) in an histogram意思。但是,由于示例中的 SNP 和 DEL 数据是二进制数据,您可能希望在条形图中绘制 SNP 和 DEL 的计数。如果这是真的,你可以试试这个方法:

mybarplot <- function(mydata, x) {
  (ggplot(mydata, aes_string(x = x)) + geom_bar()
  + theme(plot.margin = unit(c(0.5, 0.5, 0, 0), "cm"), 
          legend.key.size = unit(0.4, "cm")))
}

该函数将一个数据框及其一列作为其输入,并生成一个条形图作为其输出。然后,你在你的函数中调用这个函数upset来生成条形图和你的不安图。

upset(dftest, attribute.plots = list(gridrows = 50, 
                                     plots = list(list(plot = mybarplot, 
                                                       x = "type"))))

结果图

于 2021-08-11T16:25:06.250 回答