本文介绍了R:ggplot:错误:未知参数:binwidth,bin,pad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用ggplot2做一个非常简单的直方图。我有以下MWE:

 库(ggplot2)
mydf< - data.frame(
基因= c(APC,FAT4,XIRP2,TP53,CSMD3,BAI3,LRRK2,MACF1,
TRIO,SETD2 ,APF,ERBB4,FBXW7,NF1,PDE4DIP,
PTPRT,SPEN,ATM,FAT1,SDK1,SMG1 GLI3,HIF1A,ROS1,
BRDT,CDH11,CNTRL,EP400,FN1,GNAS,LAMA1,PIK3CA $ bPOLE,PRDM16,ROCK2,TRRAP,BRCA2,DCLK1,EVC2,LIFR,
MAST4,NAV3 b Freq = c(48,39,35,28,26,17,17,17,16,15,14,14,14,14,14,14,14,13,
13,13 ,13,12,12,12,11,11,11,11,11,11,11,11,11,11,11,10,10,10,
10,10,10))
mydf
ggplot(mydf,aes(x = Gene))+
geom_histogram(aes(y = Freq),
stat =identity,
binwidth = .5,alpha = .5,
position =identity)

我有总是使用这个简单的代码来生成这种直方图。



事实上,我有一段时间以前提到的这个特例的情节...





但是,现在我运行这个完全相同的代码,我收到以下错误:

为什么我现在发现这个错误,而不是之前,这是什么意思?



非常感谢! >

解决方案

我宁愿使用 dplyr (管道操作符)来清楚地了解代码:

  mydf%>%#my data frame 
as.data.frame%>%#if mydf不是数据帧
ggplot(aes(x = Var,y = n))
+ geom_bar(aes(y = n),stat =id实体,position =identity)


I want to do a very simple histogram with ggplot2. I have the following MWE:

library(ggplot2)
mydf <- data.frame(
                  Gene=c("APC","FAT4","XIRP2","TP53","CSMD3","BAI3","LRRK2","MACF1",
                  "TRIO","SETD2","AKAP9","CENPF","ERBB4","FBXW7","NF1","PDE4DIP",
                  "PTPRT","SPEN","ATM","FAT1","SDK1","SMG1","GLI3","HIF1A","ROS1",
                  "BRDT","CDH11","CNTRL","EP400","FN1","GNAS","LAMA1","PIK3CA",
                  "POLE","PRDM16","ROCK2","TRRAP","BRCA2","DCLK1","EVC2","LIFR",
                  "MAST4","NAV3"),
                  Freq=c(48,39,35,28,26,17,17,17,16,15,14,14,14,14,14,14,14,14,13,
                  13,13,13,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,10,10,10,
                  10,10,10))
mydf
ggplot(mydf, aes(x=Gene)) +
      geom_histogram(aes(y=Freq),
      stat="identity",
      binwidth=.5, alpha=.5,
      position="identity")

I have always used this simple code to produce this kind of histograms.

In fact, I have the plot for this particular example that I made some time ago...

However, now I run this exact same code, and I get the following error:

Why do I find this error now and not before, and what does it mean?

Thanks a lot!

解决方案

I rather would use dplyr (pipe operator) for clear understanding of the code:

   mydf %>%  #my data frame
     as.data.frame %>%  #if mydf is not a dataframe
     ggplot(aes(x = Var, y = n))
       + geom_bar( aes(y = n), stat = "identity", position = "identity")

这篇关于R:ggplot:错误:未知参数:binwidth,bin,pad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 20:44