今天打算画一个barplot,然后加上方差,后来想要把背景去掉,加上theme主题,结果发现总会报错,Error in inherits(x, “theme”) : argument “e2” is missing, with no default
搞了两个小时,终于发现错误的原因并不是网页上说的加号太多了,需要写到一起去,而是需要分开写才可以,下面将把具体代码演示如下,如果小伙伴遇到类似问题,可以参考一下。
ID Symbol sunlight control
1 L1 1.8092 3.54
2 I2 27.3529 4.408
3 G 1.4845 0.7348
4 5G 32.0455 57.7454
5 ST 19.6581 4.8752
library(ggplot2)
library(plyr)
library(reshape2)
data<-read.csv(“rnaseq.csv”,header=TRUE)
melted <- melt(data, id.vars=c(“ID”, “Symbol”))
value_log<-log(melted$value,2)
melted<-cbind(melted,value_log)
means <- ddply(melted, c(“Symbol”, “variable”), summarise,
mean=mean(value_log))
===================================
means.barplot <- qplot(x=Symbol, y=mean, fill=variable,
data=means, geom=”bar”, stat=”identity”,
position=”dodge”,ylab=”log(Mean Expression of genes)”)
means.barplot +
theme(panel.background = element_rect(fill = “transparent”, color = “gray”),
legend.key = element_rect(fill = “transparent”, color = “transparent”),
axis.text = element_text(color = “black”))
===========这样操作不会出现错误============
means.sem <- ddply(melted, c(“Symbol”, “variable”), summarise,
mean=mean(value_log), sem=sd(value_log)/sqrt(length(value_log)))
means.sem <- transform(means.sem, lower=mean-sem, upper=mean+sem)
means.barplot + geom_errorbar(aes(ymax=upper,
ymin=lower),
position=position_dodge(0.9),
data=means.sem)
==================这样也不会报错=================
但是,如果执行如下代码,即同时加上方差项和把背景改为白色就会报错
means.barplot + geom_errorbar(aes(ymax=upper,
ymin=lower),
position=position_dodge(0.9),
data=means.sem)
+ theme(panel.background = element_rect(fill = “transparent”, color = “gray”),
legend.key = element_rect(fill = “transparent”, color = “transparent”),
axis.text = element_text(color = “black”))
就会在console处出现Error in inherits(x, “theme”) : argument “e2” is missing, with no default这样从错误,并且最后一行不会执行;
想要解决这样的问题,一个比较简单的方案是分开放到不同的变量里面去
代码展示如下:
p<-means.barplot + geom_errorbar(aes(ymax=upper,
ymin=lower),
position=position_dodge(0.9),
data=means.sem)
+ theme(panel.background = element_rect(fill = “transparent”, color = “gray”),
legend.key = element_rect(fill = “transparent”, color = “transparent”),
axis.text = element_text(color = “black”))
p+ theme(panel.background = element_rect(fill = “transparent”, color = “gray”),
legend.key = element_rect(fill = “transparent”, color = “transparent”),
axis.text = element_text(color = “black”))
这样操作,图就会正常出来了