图使用ggplot2

时间:2015-08-25 14:20:17

标签: r ggplot2

我在尝试使用ggplot2包时遇到了麻烦。我得到的所有图表都是空的

ggplot(data=dataa,aes(x=Description, y=RPKM,fill=Condition)) + 
  geom_bar(position="dodge",stat="identity")

dataa是一个更大的数据框架,如下所示:

Description Tissue  Condition   RPKM
re           brain  obese       34
re1          brain  Fit         23
re2          brain  Slim        67

知道我做错了什么?

我拥有的真实数据:

Description Tissue  Condition   RPKM 
peptidase Brain Obese   0.5
protein Brain   Obese   1.4 
Glucagon    Brain   Fit 0.06 
kinase  Brain   Fit 0.9 
transporter Brain   Obese   4.8 
Secretogran Brain   Slim    87.2 

脚本:

tissues<-factor(unique(RPKMl123upslim$Tissue)) 
for (n in 1:6) { 
    i=c(0,108,216,324,432,540) 
    #datos<-data.frame(RPKMl123upslim[(i[n]+1):(i[n]+108),]) 
    View(datos) 
    ggplot(data=datos,aes(x=Description, y=Expression,fill=Condition)) + 
        geom_bar(position="dodge",stat="identity", colour="black",las=2) 

    path100<-file.path("pajarito",paste("Lupslimrpkm_",tissues[n],".jpg", sep=" ")) 
    jpeg(file=path100) 
    dev.off() 
} 

- Roberto Carlos 2天前

2 个答案:

答案 0 :(得分:0)

library(ggplot2)
dataa <- data.frame(Description =c("re","re1","re2")
          ,Condition=c("Obese","Fit","Slim"),RPKM=c(34,23,67))

ggplot(data=dataa,aes(x=Description, y=RPKM,fill=Condition))+ 
         geom_bar(position="dodge",stat="identity")`

这就是我得到的

enter image description here

答案 1 :(得分:0)

感谢您的帮助,现在我想分享有效的代码:

 dev.set(dev.prev()) 
#dev.new(width=10, height=12)
 path100<-file.path("D:","final.results",paste("skin005",".png", sep=" "))
 png(file=path100, width=1000, height=10000, res=100)
plot(1:100)
attach(skin005RPKMS) #previous data frame with all information
q<-skin005RPKMS[(Skin.Obese > Skin.Fit) & (Skin.Obese > Skin.Slim),]
colnames(q)<-c("Description","Skin.Slim","Skin.Fit","Skin.Obese")
q1<-melt(q,id.vars="Description") #variable contain the different condition    of the experiment and value the data.
p <- ggplot(q1, aes(y=Description,x=variable))+ geom_tile(aes(fill=value)) +   scale_fill_gradientn(colours=c("white","azure2","yellow","blue","orchid","orange red","red","black"), values=rescale(c(0,1,10,50,100,500,1000,4500)),  guide="colorbar") + xlab("Condition") + ylab("Genes")
print(p)
dev.off()