[R] qplot/ggplot

arun smartpink111 at yahoo.com
Sat Jul 21 05:07:25 CEST 2012


Hello,

You can try either one of these methods::
#Simple line plot
dat1<-read.table(text="
Gene1 10 14 12 23 11 11 33 1
Gene2 4 2 1 1 3 4 1 2
Gene3 2 5 7 5 6 89 7 3
Gene4 1 9 8 3 90 8 8 5
",sep="",header=FALSE,stringsAsFactors=FALSE)
dat2<-as.data.frame(t(dat1[,-1]))
 colnames(dat2)<-paste("Gene",1:4,sep="")
 rownames(dat2)<-1:nrow(dat2)
str(dat2)
dat3<-data.frame(dat2,index=1:8)

 plot(0,type="n",main="Genes line plot",ylab="Expression",xlim=c(0,10),ylim=c(0,100)) 

lines(dat3$index,dat3$Gene1,col="orange")
 lines(dat3$index,dat3$Gene2,col="green")
 lines(dat3$index,dat3$Gene3,col="blue")
 lines(dat3$index,dat3$Gene4,col="red")
 points(dat3$index,dat3$Gene1,col="orange",pch=1)
 points(dat3$index,dat3$Gene2,col="green",pch=2)
 points(dat3$index,dat3$Gene3,col="blue",pch=3)
  points(dat3$index,dat3$Gene4,col="red",pch=4)
legend("topright",c("Gene1","Gene2","Gene3","Gene4"),col=c("orange","green","blue","red"),lty=1,pch=c(1:4))


#ggplot
library(ggplot2)
dat3mlt<-melt(dat3,id.vars="index")
#1
   ggplot(dat3mlt, aes(x=index, y=value, colour=variable))+stat_smooth(method="lm")+geom_point()
#2
ggplot(dat3mlt, aes(x=index, y=value, colour=variable))+stat_smooth(method="lm",formula=y~ns(x,3))+geom_point()
#3
ggplot(dat3mlt, aes(x=index, y=value, colour=variable))+stat_smooth(fill="green",size=2)+geom_point()



Hope this helps you.
A.K.




----- Original Message -----
From: Anamika K <anamikarti at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Friday, July 20, 2012 6:57 AM
Subject: [R] qplot/ggplot

Hello,
I have a file like this (just a snapshot) where I have numerical
values for various genes, I want a line plot with shading (may be
using smooth ?) using qplot or ggplot :

Gene1 10 14 12 23 11 11 33 1 ......(multiple columns)
Gene2 4 2 1 1 3 4 1 2 .....
Gene3 2 5 7 5 6 89 7 3 ......
Gene4 1 9 8 3 90 8 8  .....

Please help.

Ana

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list