[R-sig-teaching] plot an angle of 450 degrees and adding a circular arrow to it
Joel Schwartz
joel at joelschwartz.com
Tue Oct 21 20:44:58 CEST 2014
Steven,
Change
abline(x1,y1, lwd = 3) to lines(x1,y1, lwd = 3) and you'll get the line you're looking for. abline is just for drawing a line with a given slope and intercept. lines is more general.
Also, c(-4*pi,-(7*pi)/2,-3*pi,-(5*pi)/2,-2*pi,-(3*pi)/2,-pi,-pi/2, 0,pi/2,pi,(3*pi)/2,2*pi,(5*pi)/2,3*pi,(7*pi)/2,4*pi)
can be done with a call to seq instead. For example:
seq(-4*pi, 4*pi, pi/2)
Best Wishes,
Joel
On Oct 21, 2014, at 11:30 AM, Steven Stoline <sstoline at gmail.com> wrote:
> Dear Jones:
>
> Could you please look to this R code. I am trying to graph both sin(x+pi/6)
> and sin(x) in the same plot to show the shift. I used abline to graph the
> sin(x), but it looked like same as the x-axis.
>
>
> x<-seq(-2.2*pi,2*pi,0.01)
> y<-sin(x+pi/6)
>
>
> #### To draw a box of the graph:
> #### ==========================
>
> plot(0:10, 0:10, type = "n", xaxt = "n", yaxs = "i", xaxs = "i", yaxt =
> "n", xlab = "", ylab = "")
>
> plot(x, y, type='l', lwd = 3, col="red", xaxt = "n", xlab="", ylab="")
>
>
>
> #### abline(v=c(-4*pi,-(7*pi)/2,-3*pi,-(5*pi)/2,-2*pi,-(3*pi)/2,-pi,-pi/2,
> 0,pi/2,pi,(3*pi)/2,2*pi,(5*pi)/2,3*pi,(7*pi)/2,4*pi),col="blue")
>
>
> abline(h=0, lwd=3)
> abline(v=0, lwd=3)
>
>
> x1<-seq(0,2*pi,0.01)
> y1<-sin(x1)
> abline(x1,y1, lwd = 3)
>
>
> thank you very much
> Steven
>
>
> On Mon, Oct 20, 2014 at 1:08 PM, Steven Stoline <sstoline at gmail.com> wrote:
>
>> Many thanks
>>
>> it works
>>
>> Steven
>>
>> On Mon, Oct 20, 2014 at 11:17 AM, Albyn Jones <jones at reed.edu> wrote:
>>
>>> Here is a quickly written and barely tested function. You might want to
>>> add a final position vector,
>>> color, lwd, lty, etc. It assumes the angle is given in degrees, and
>>> checks the sign of the angle to draw
>>> in the correct direction.
>>>
>>> albyn
>>> =====================================================================
>>>
>>> DrawAngle <- function(theta,r=1){
>>> # assumes angles given in degrees, not radians
>>> theta <- 2*pi*theta/360
>>> plot(0,0, xlim=c(-2,2),ylim=c(-2,2))
>>> abline(h=0)
>>> abline(v=0)
>>> sgn <- 1
>>> if(theta <0) {
>>> sgn <- -1
>>> theta <- -theta
>>> }
>>> Theta <- sgn*seq(0,theta,.01)
>>> if(theta > 2*pi) r <- seq(1,1.1,along.with=Theta)
>>> x <- r*cos(Theta)
>>> y <- r*sin(Theta)
>>> lines(x,y)
>>> n <- length(x)
>>> arrows(x[n-1],y[n-1],x[n],y[n])
>>> }
>>>
>>> On Mon, Oct 20, 2014 at 1:47 AM, Steven Stoline <sstoline at gmail.com>
>>> wrote:
>>>
>>>> Dear All:
>>>>
>>>> I am wondering if someone can show me how to plot an angles around the
>>>> center of a unit circle with x-y vertices added to it.
>>>>
>>>> Also how to add arrows showing the size and the direction of angle(s).
>>>>
>>>> Examples: 135 degrees and 450 degrees angles.
>>>>
>>>> with many thanks
>>>> Steven
>>>>
>>>> --
>>>> Steven M. Stoline
>>>> 1123 Forest Avenue
>>>> Portland, ME 04112
>>>> sstoline at gmail.com
>>>>
>>>> [[alternative HTML version deleted]]
>>>>
>>>> _______________________________________________
>>>> R-sig-teaching at r-project.org mailing list
>>>> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
>>>>
>>>
>>>
>>
>>
>> --
>> Steven M. Stoline
>> 1123 Forest Avenue
>> Portland, ME 04112
>> sstoline at gmail.com
>>
>
>
>
> --
> Steven M. Stoline
> 1123 Forest Avenue
> Portland, ME 04112
> sstoline at gmail.com
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-teaching at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-teaching
More information about the R-sig-teaching
mailing list