Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 Similar Threads Thread Thread Starter Forum Replies Last Post pirates.genome Bioinformatics 2 05-15-2014 09:56 PM aevgup Bioinformatics 1 04-21-2014 02:06 PM sazz Bioinformatics 3 07-20-2013 08:44 AM stephenhart General 0 12-06-2012 03:07 AM bioenvisage General 1 02-15-2010 10:12 AM

04-25-2014, 10:26 AM   #1
aevgup
Member

Location: usa

Join Date: Jul 2011
Posts: 17
Plotting in R

Hi Everyone,

I am trying to plot a histogram in R using this command which is serving my purpose

When you look at the graph(see attached) then from 715 to 777 is my CODING REGION. I want to make a rectangular bar from position 715-777 and place it on the top of the graph. How can I do it

I wrote this and try to add lines or points but was not able to do it
firstCodonCdr1 = 239
lastCodonCdr1 = 259
cdr1NTs = ((firstCodonCdr1-1)*3+1)3*lastCodonCdr1)
cdrPositions = cdr1NTs

Any help !!

Thanks
Attached Images
 cov.png (3.7 KB, 10 views)

Last edited by aevgup; 04-25-2014 at 10:41 AM.

 04-25-2014, 10:49 AM #2 blakeoft Member   Location: Connecticut Join Date: Oct 2013 Posts: 79 I think you want to use the polygon function. See ?polygon to look at the help info. Basically: Code: `polygon(x,y,col)` where x is the vector containing x coordinates of the vertices, y is y vertices and col is the color of the polygon. I think you'll plot your histogram, and then polygon() right after it. So it'll look like: Code: ```> hist(data) > polygon(x,y,col)``` Last edited by blakeoft; 04-25-2014 at 10:51 AM.
04-25-2014, 10:57 AM   #3
aevgup
Member

Location: usa

Join Date: Jul 2011
Posts: 17
plotting in R

Hi I used this code

firstCodonCdr1 = 239
lastCodonCdr1 = 259
cdr1NTs = ((firstCodonCdr1-1)*3+1)3*lastCodonCdr1)
cdrPositions = cdr1NTs

plot(x\$V2,x\$V3,type="h",col="blue")
r = rep(50,63) # to make 63 times 50 to occur so that it matches length of x
par(new=TRUE)

polygon(cdrPositions,r,col="red")

No change happens in the graph.

I am attaching the cov.txt file too

I have been trying points and lines too but no luck!!

THanks
Attached Images
 cov.png (3.7 KB, 6 views)
Attached Files
 cov.txt (3.1 KB, 4 views)

04-25-2014, 11:18 AM   #4
blakeoft
Member

Location: Connecticut

Join Date: Oct 2013
Posts: 79

This looks terrible, but I just did
Code:
```> x <- read.table(file="cov.txt",header =FALSE)
> plot(x\$V2,x\$V3,type="h",col="blue")
> polygon(c(715,777,777,715),c(40,40,45,45), col="blue")```
and got this picture. You can change the coordinates of the box if you want so that it doesn't look as bad, and also, the color might need some work. I think you can do it like col = rgb(a,b,c) where a b and c are the red blue and green color values.
Attached Images
 bar_on_hist.png (12.3 KB, 9 views)

04-25-2014, 11:31 AM   #5
aevgup
Member

Location: usa

Join Date: Jul 2011
Posts: 17

Quote:
Regards
Attached Images
 cov2.png (3.7 KB, 10 views)

 04-29-2014, 04:57 AM #6 Thias Member   Location: Münster, Germany Join Date: Mar 2013 Posts: 42 Seems your problem is already solved, but in case you have 5o plot similar data in future again, I recommend the Gviz package on Bioconductor, which can be used to output beautiful plots for NGS-data.
 04-29-2014, 06:41 AM #7 aevgup Member   Location: usa Join Date: Jul 2011 Posts: 17 Hi, Thanks for letting me know about the package. I am trying this package now

 Tags plot