Quantcast

Circular plot

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Circular plot

Swaraj
I want to plot segments deleted from mitochondrial DNA of patients with
neuromuscular disorders. I generate the plot on a linear chromosome using a
code similar to as shown below

start<-c(1,5,600,820)
end<-c(250,75,810,1200)
score<-c(7,-1,4,-6.5)
dat<-data.frame(start=start,end=end,score=score,col="blue",stringsAsFactors=F)
dat[dat$score<0,]$col<-"red"

plot(1:1500,rep(0,1500),type="p",ylim=c(-10,10),col="white",xlab="position",ylab="score")
segments(dat$start, dat$score, dat$end, dat$score, col=dat$col, lwd=3)


Since the human mitochondria is a circular genome, I would like to
visualise the plot generated above as a circle where all segments with
positive score lie inside the circle and those with negative score lie
outside. Attached is a representation of my requirement, although here it
is manually drawn. Can someone help me on this?


--
Swaraj Basu

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

example.pdf (43K) Download Attachment
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Circular plot

David Carlson
You can do this easily with the DrawCircle() function in package DescTools. It is easiest to use geometric coordinates (0 is at 3 o'clock and moves counterclockwise around the circle), but it could be converted to 12 o'clock and clockwise:

library(DescTools)

# Convert begin/stop to radians
dat$begin <- 0 + 2 * pi * dat$start/1500
dat$stop <- 0 + 2 * pi * dat$end/1500

# Open blank plot window and draw circles
Canvas(xlim = c(-5,5), xpd=TRUE)
DrawCircle (r.out = 5, r.in = 5, theta.1=.05, theta.2=2*pi-.05, lwd=3)
with(dat, DrawCircle(r.out = 5 - score/5, r.in = 5 - score/5,
     theta.1=begin, theta.2=stop, border=col, lwd=4))
text(5.2, .4, "1", pos=4)
text(5.2, -.4, "1500", pos=4)

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352




-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of swaraj basu
Sent: Monday, February 13, 2017 10:34 AM
To: [hidden email]
Subject: [R] Circular plot

I want to plot segments deleted from mitochondrial DNA of patients with
neuromuscular disorders. I generate the plot on a linear chromosome using a
code similar to as shown below

start<-c(1,5,600,820)
end<-c(250,75,810,1200)
score<-c(7,-1,4,-6.5)
dat<-data.frame(start=start,end=end,score=score,col="blue",stringsAsFactors=F)
dat[dat$score<0,]$col<-"red"

plot(1:1500,rep(0,1500),type="p",ylim=c(-10,10),col="white",xlab="position",ylab="score")
segments(dat$start, dat$score, dat$end, dat$score, col=dat$col, lwd=3)


Since the human mitochondria is a circular genome, I would like to
visualise the plot generated above as a circle where all segments with
positive score lie inside the circle and those with negative score lie
outside. Attached is a representation of my requirement, although here it
is manually drawn. Can someone help me on this?


--
Swaraj Basu

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

mtDNAplot.png (7K) Download Attachment
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Circular plot

Bert Gunter-2
In reply to this post by Swaraj
If you don't get a reply here:

1. Search! (try rseek.org as an R search engine).

2. Try the Bioconductor list. As this appears to be closer to their
realm, they may have what you're looking for.


Cheers,
Bert
Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Mon, Feb 13, 2017 at 8:33 AM, swaraj basu <[hidden email]> wrote:

> I want to plot segments deleted from mitochondrial DNA of patients with
> neuromuscular disorders. I generate the plot on a linear chromosome using a
> code similar to as shown below
>
> start<-c(1,5,600,820)
> end<-c(250,75,810,1200)
> score<-c(7,-1,4,-6.5)
> dat<-data.frame(start=start,end=end,score=score,col="blue",stringsAsFactors=F)
> dat[dat$score<0,]$col<-"red"
>
> plot(1:1500,rep(0,1500),type="p",ylim=c(-10,10),col="white",xlab="position",ylab="score")
> segments(dat$start, dat$score, dat$end, dat$score, col=dat$col, lwd=3)
>
>
> Since the human mitochondria is a circular genome, I would like to
> visualise the plot generated above as a circle where all segments with
> positive score lie inside the circle and those with negative score lie
> outside. Attached is a representation of my requirement, although here it
> is manually drawn. Can someone help me on this?
>
>
> --
> Swaraj Basu
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Circular plot

Swaraj
In reply to this post by David Carlson
Thank you David, I could get the circle at 12 and clockwise however I
believe my solution is not the optimal one, could you help me out with the
best way to generate the circle clockwise at 12 and then convert the
begin/stop to radians

Here is what I tried

par(mar=c(2,2,2,2),xpd=TRUE);
plot(c(1,800),c(1,800),type="n",axes=FALSE,xlab="",ylab="",main="");
DrawCircle (x=400,y=400,r.out = 400, r.in = 400, theta.1=1.57,
theta.2=-2*pi-4.67, lwd=1)

On Mon, Feb 13, 2017 at 6:52 PM, David L Carlson <[hidden email]> wrote:

> You can do this easily with the DrawCircle() function in package
> DescTools. It is easiest to use geometric coordinates (0 is at 3 o'clock
> and moves counterclockwise around the circle), but it could be converted to
> 12 o'clock and clockwise:
>
> library(DescTools)
>
> # Convert begin/stop to radians
> dat$begin <- 0 + 2 * pi * dat$start/1500
> dat$stop <- 0 + 2 * pi * dat$end/1500
>
> # Open blank plot window and draw circles
> Canvas(xlim = c(-5,5), xpd=TRUE)
> DrawCircle (r.out = 5, r.in = 5, theta.1=.05, theta.2=2*pi-.05, lwd=3)
> with(dat, DrawCircle(r.out = 5 - score/5, r.in = 5 - score/5,
>      theta.1=begin, theta.2=stop, border=col, lwd=4))
> text(5.2, .4, "1", pos=4)
> text(5.2, -.4, "1500", pos=4)
>
> -------------------------------------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
>
>
>
> -----Original Message-----
> From: R-help [mailto:[hidden email]] On Behalf Of swaraj
> basu
> Sent: Monday, February 13, 2017 10:34 AM
> To: [hidden email]
> Subject: [R] Circular plot
>
> I want to plot segments deleted from mitochondrial DNA of patients with
> neuromuscular disorders. I generate the plot on a linear chromosome using a
> code similar to as shown below
>
> start<-c(1,5,600,820)
> end<-c(250,75,810,1200)
> score<-c(7,-1,4,-6.5)
> dat<-data.frame(start=start,end=end,score=score,col="blue"
> ,stringsAsFactors=F)
> dat[dat$score<0,]$col<-"red"
>
> plot(1:1500,rep(0,1500),type="p",ylim=c(-10,10),col="white",
> xlab="position",ylab="score")
> segments(dat$start, dat$score, dat$end, dat$score, col=dat$col, lwd=3)
>
>
> Since the human mitochondria is a circular genome, I would like to
> visualise the plot generated above as a circle where all segments with
> positive score lie inside the circle and those with negative score lie
> outside. Attached is a representation of my requirement, although here it
> is manually drawn. Can someone help me on this?
>
>
> --
> Swaraj Basu
>



--
Swaraj Basu

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Circular plot

Jim Lemon-4
Hi Swaraj,
As David pointed out, you can get the arcs without too much trouble:

library(plotrix)
mdf<-data.frame(score=c(-1,7,4,-7),start=c(0,0,600,800),
 finish=c(100,200,800,1250))
par(mar=c(4,4,1,1))
plot(0,type="n",xlim=c(-20,20),ylim=c(-20,20),xlab="",ylab="",
 xaxt="n",yaxt="n")
axis(1,at=c(-20,-10,0,10,20),labels=c(10,0,-10,0,10))
axis(2,at=c(-20,-10,0,10,20),labels=c(10,0,-10,0,10))
draw.circle(0,0,10,lty=2,border="black")
mlength<-1500
for(i in 1:dim(mdf)[1]) {
draw.arc(0,0,10+mdf$score[i],
 angle1=2*pi*mdf$start[i]/mlength,
 angle2=2*pi*mdf$finish[i]/mlength,
 lwd=3,col=ifelse(mdf$score[i]<0,"red","blue"))
}

However, you may want a circular grid as well as clockwise angles:

par(mar=c(1,1,1,1))
plot(0,type="n",xlim=c(-6,6),ylim=c(-6,6),
 xlab="",ylab="",axes=FALSE)
radial.grid(seq(0,1250,by=250),radial.lim=c(0,10),
 label.pos=seq(0,12.5/15,by=2.5/15)*2*pi,
 grid.pos=seq(0,12.5/15,by=2.5/15)*2*pi,
 start=pi/2,clockwise=TRUE)
for(i in 1:dim(mdf)[1]) {
 draw.arc(0,0,(10+mdf$score[i])/4.5,
  deg1=450-360*mdf$start[i]/mlength,
  deg2=450-360*mdf$finish[i]/mlength,
  lwd=3,col=ifelse(mdf$score[i]<0,"red","blue"))
}

Both of these examples are pretty messy, but could be improved if you
have a lot of work like this.

Jim


On Tue, Feb 14, 2017 at 8:58 AM, swaraj basu <[hidden email]> wrote:

> Thank you David, I could get the circle at 12 and clockwise however I
> believe my solution is not the optimal one, could you help me out with the
> best way to generate the circle clockwise at 12 and then convert the
> begin/stop to radians
>
> Here is what I tried
>
> par(mar=c(2,2,2,2),xpd=TRUE);
> plot(c(1,800),c(1,800),type="n",axes=FALSE,xlab="",ylab="",main="");
> DrawCircle (x=400,y=400,r.out = 400, r.in = 400, theta.1=1.57,
> theta.2=-2*pi-4.67, lwd=1)
>
> On Mon, Feb 13, 2017 at 6:52 PM, David L Carlson <[hidden email]> wrote:
>
>> You can do this easily with the DrawCircle() function in package
>> DescTools. It is easiest to use geometric coordinates (0 is at 3 o'clock
>> and moves counterclockwise around the circle), but it could be converted to
>> 12 o'clock and clockwise:
>>
>> library(DescTools)
>>
>> # Convert begin/stop to radians
>> dat$begin <- 0 + 2 * pi * dat$start/1500
>> dat$stop <- 0 + 2 * pi * dat$end/1500
>>
>> # Open blank plot window and draw circles
>> Canvas(xlim = c(-5,5), xpd=TRUE)
>> DrawCircle (r.out = 5, r.in = 5, theta.1=.05, theta.2=2*pi-.05, lwd=3)
>> with(dat, DrawCircle(r.out = 5 - score/5, r.in = 5 - score/5,
>>      theta.1=begin, theta.2=stop, border=col, lwd=4))
>> text(5.2, .4, "1", pos=4)
>> text(5.2, -.4, "1500", pos=4)
>>
>> -------------------------------------
>> David L Carlson
>> Department of Anthropology
>> Texas A&M University
>> College Station, TX 77840-4352
>>
>>
>>
>>
>> -----Original Message-----
>> From: R-help [mailto:[hidden email]] On Behalf Of swaraj
>> basu
>> Sent: Monday, February 13, 2017 10:34 AM
>> To: [hidden email]
>> Subject: [R] Circular plot
>>
>> I want to plot segments deleted from mitochondrial DNA of patients with
>> neuromuscular disorders. I generate the plot on a linear chromosome using a
>> code similar to as shown below
>>
>> start<-c(1,5,600,820)
>> end<-c(250,75,810,1200)
>> score<-c(7,-1,4,-6.5)
>> dat<-data.frame(start=start,end=end,score=score,col="blue"
>> ,stringsAsFactors=F)
>> dat[dat$score<0,]$col<-"red"
>>
>> plot(1:1500,rep(0,1500),type="p",ylim=c(-10,10),col="white",
>> xlab="position",ylab="score")
>> segments(dat$start, dat$score, dat$end, dat$score, col=dat$col, lwd=3)
>>
>>
>> Since the human mitochondria is a circular genome, I would like to
>> visualise the plot generated above as a circle where all segments with
>> positive score lie inside the circle and those with negative score lie
>> outside. Attached is a representation of my requirement, although here it
>> is manually drawn. Can someone help me on this?
>>
>>
>> --
>> Swaraj Basu
>>
>
>
>
> --
> Swaraj Basu
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Circular plot

David Carlson
In reply to this post by Swaraj
This is pretty close to your original plot. To get clockwise we multiply the radians by -1 and then add pi/2 to move the origin to 12 o'clock. We need to flip the start and end values since now we are be plotting from the end to the start:

start<-c(1,5,600,820)
end<-c(250,75,810,1200)
score<-c(7,-1,4,-6.5)
dat<-data.frame(start=start,end=end,score=score,col="blue",stringsAsFactors=F)
dat[dat$score<0,]$col<-"red"

# Convert begin/stop to radians
dat$stop <- -(2 * pi * dat$start/1500) + pi/2
dat$begin <- -(2 * pi * dat$end/1500) + pi/2

# Open blank plot window and draw circles
Canvas(xlim = c(-5,5), xpd=TRUE)
DrawCircle (r.out = 5, r.in = 5, theta.1=pi/2+.05, theta.2=pi*5/2-.05, lwd=3)
with(dat, DrawCircle(r.out = 5 - score/5, r.in = 5 - score/5,
     theta.1= begin, theta.2= stop, border=col, lwd=4))
text(.1, 5.5, "1", pos=4)
text(-.1, 5.5, "1500", pos=2)

David C


From: swaraj basu [mailto:[hidden email]]
Sent: Monday, February 13, 2017 3:58 PM
To: David L Carlson <[hidden email]>; [hidden email]
Subject: Re: [R] Circular plot

Thank you David, I could get the circle at 12 and clockwise however I believe my solution is not the optimal one, could you help me out with the best way to generate the circle clockwise at 12 and then convert the begin/stop to radians

Here is what I tried

par(mar=c(2,2,2,2),xpd=TRUE);
plot(c(1,800),c(1,800),type="n",axes=FALSE,xlab="",ylab="",main="");
DrawCircle (x=400,y=400,r.out = 400, r.in = 400, theta.1=1.57, theta.2=-2*pi-4.67, lwd=1)

On Mon, Feb 13, 2017 at 6:52 PM, David L Carlson <[hidden email]> wrote:
You can do this easily with the DrawCircle() function in package DescTools. It is easiest to use geometric coordinates (0 is at 3 o'clock and moves counterclockwise around the circle), but it could be converted to 12 o'clock and clockwise:

library(DescTools)

# Convert begin/stop to radians
dat$begin <- 0 + 2 * pi * dat$start/1500
dat$stop <- 0 + 2 * pi * dat$end/1500

# Open blank plot window and draw circles
Canvas(xlim = c(-5,5), xpd=TRUE)
DrawCircle (r.out = 5, r.in = 5, theta.1=.05, theta.2=2*pi-.05, lwd=3)
with(dat, DrawCircle(r.out = 5 - score/5, r.in = 5 - score/5,
     theta.1=begin, theta.2=stop, border=col, lwd=4))
text(5.2, .4, "1", pos=4)
text(5.2, -.4, "1500", pos=4)

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352




-----Original Message-----
From: R-help [mailto:[hidden email]] On Behalf Of swaraj basu
Sent: Monday, February 13, 2017 10:34 AM
To: [hidden email]
Subject: [R] Circular plot

I want to plot segments deleted from mitochondrial DNA of patients with
neuromuscular disorders. I generate the plot on a linear chromosome using a
code similar to as shown below

start<-c(1,5,600,820)
end<-c(250,75,810,1200)
score<-c(7,-1,4,-6.5)
dat<-data.frame(start=start,end=end,score=score,col="blue",stringsAsFactors=F)
dat[dat$score<0,]$col<-"red"

plot(1:1500,rep(0,1500),type="p",ylim=c(-10,10),col="white",xlab="position",ylab="score")
segments(dat$start, dat$score, dat$end, dat$score, col=dat$col, lwd=3)


Since the human mitochondria is a circular genome, I would like to
visualise the plot generated above as a circle where all segments with
positive score lie inside the circle and those with negative score lie
outside. Attached is a representation of my requirement, although here it
is manually drawn. Can someone help me on this?


--
Swaraj Basu




--
Swaraj Basu

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

mtDNAplot.png (6K) Download Attachment
Loading...