Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 如何在条形图中绘制表格摘要_R_Graph_Bar Chart - Fatal编程技术网

R 如何在条形图中绘制表格摘要

R 如何在条形图中绘制表格摘要,r,graph,bar-chart,R,Graph,Bar Chart,我有一个单核苷酸多态性表和相应基因的信息:基因ID、基因类型和基因名称: SNP Gene ID Gene type Gene Name 1 rs10876864 ENSG00000123411.10 protein_coding IKZF4 2 rs10876864 ENSG00000123411.10 protein_coding IKZF4 3 rs1087

我有一个单核苷酸多态性表和相应基因的信息:基因ID、基因类型和基因名称:

          SNP            Gene ID         Gene type      Gene Name
1    rs10876864 ENSG00000123411.10    protein_coding          IKZF4
2    rs10876864 ENSG00000123411.10    protein_coding          IKZF4
3    rs10876864 ENSG00000123411.10    protein_coding          IKZF4
4    rs10876864 ENSG00000123411.10    protein_coding          IKZF4
5   CNVR2845.57  ENSG00000196126.6    protein_coding       HLA-DRB1
6   CNVR2845.57  ENSG00000196126.6    protein_coding       HLA-DRB1
7   CNVR2845.57  ENSG00000196126.6    protein_coding       HLA-DRB1
8   CNVR2845.57  ENSG00000196126.6    protein_coding       HLA-DRB1
9     rs6030897  ENSG00000201372.1             snRNA             U6
10    rs6030897  ENSG00000201372.1             snRNA             U6
11    rs6030897  ENSG00000201372.1             snRNA             U6
我想画一个SNPs总数的条形图,看看有多少SNPs是蛋白质编码或snRNA等

这是我目前的代码:

barplot(as.matrix(data1), main="SNP", xlab="Gene type", ylab= "Total SNP",     names.arg=c("protein_coding","snRNA","pseudogene","antisense","lincRNA",""), border="blue", density=c(10, 20, 30, 40, 50))
但我得到了一个错误,说:

Error in barplot.default(as.matrix(data1), main = "SNP", xlab = "Gene type",  :      incorrect number of names
In addition: Warning messages:
1: In apply(height, 2L, cumsum) : NAs introduced by coercion
2: In apply(height, 2L, cumsum) : NAs introduced by coercion
3: In apply(height, 2L, cumsum) : NAs introduced by coercion
4: In apply(height, 2L, cumsum) : NAs introduced by coercion
  • 您有四列,并提供5
    名称。arg
  • 密度也是一样,但单凭这一点不会出现错误
  • 根据
    ?条形图
    ,称为
    高度的
    条形图的第一项应为:

    高度
    描述构成绘图的条形图的向量或值矩阵。如果高度是一个向量,则绘图由一系列矩形条组成,其高度由向量中的值给出。如果“高度”是一个矩阵,且“旁边”为FALSE,则绘图的每个栏对应一列高度,,列中的值给出 构成钢筋的堆叠子钢筋的高度。如果高度是一个矩阵,旁边是真的, 然后将每列中的值并置,而不是堆叠

  • 您有字符列,您希望得到什么:-)?在绘制数据之前,您需要进行一些汇总统计。。。差不多

    barplot(表(df$Gene_type,df$SNP))

    但我建议大家看看其他更好的方法,当然还有
    ggplot2
    包,它可以自动完成这项工作