[R] How to draw a histogram for some intervals in R
Jim Lemon
jim at bitwrit.com.au
Tue Apr 22 02:18:11 CEST 2014
On 04/22/2014 06:32 AM, VG wrote:
> Hello Everyone,
> I have a text file which has data in this format.
>
> gene start end freq
> Slc19a1 81 144 1
> Slc19a1 192 255 6
> Slc19a1 273 336 7
> Slc19a1 363 426 4
> Slc19a1 465 528 3
> Slc19a1 540 603 5
> Slc19a1 813 876 5
> Slc19a1 912 975 6
> Slc19a1 987 1050 8
> Slc19a1 1062 1125 6
> Slc19a1 1170 1233 8
> Slc19a1 1278 1341 6
>
> I want to draw a histogram between start and end of the above files on the
> x axis and freq associated with each interval on the y axis. How can I do
> this. I am just beginning to plot graphs in R.
>
Hi VG,
Here is a very basic way to do this:
vgdf<-read.table(text="gene start end freq
Slc19a1 81 144 1
Slc19a1 192 255 6
Slc19a1 273 336 7
Slc19a1 363 426 4
Slc19a1 465 528 3
Slc19a1 540 603 5
Slc19a1 813 876 5
Slc19a1 912 975 6
Slc19a1 987 1050 8
Slc19a1 1062 1125 6
Slc19a1 1170 1233 8
Slc19a1 1278 1341 6",header=TRUE)
fbePlot<-function(ext,freq) {
plot(range(ext),range(freq),type="n",xlab="Extent",ylab="Frequency")
dimext<-dim(ext)
for(extent in 1:dimext[1])
rect(ext[extent,1],0,ext[extent,2],freq[extent])
}
fbePlot(vgdf[,c("start","end")],vgdf[,"freq"])
Jim
More information about the R-help
mailing list