[R] Plot Arrows with Angle and length

William Dunlap wdunlap at tibco.com
Wed Mar 29 17:24:31 CEST 2017


II find using complex numbers makes for less typing with
this sort of thing.  Note the use of plot(asp=1,...) to force
equal scales on both axes so the angles are right.
(I think asp=1 should have been the default when plotting complex
numbers, but too late now.)

> azimuthToNative <- function(degreesClockwise) {
+     # convert degrees clockwise from north to
+     # radians counter-clockwise from east.
+     (90-degreesClockwise)/180*base::pi
+ }
> start <- complex(real=x, imaginary=y)
> end <- start + complex(modulus = Length, argument = azimuthToNative(Azimuth))
> plot(c(start, end), type="n", asp=1) # asp=1 => equal scaling on both axes
> arrows(Re(start),Im(start),Re(end),Im(end)) # no complex method for arrows
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Wed, Mar 29, 2017 at 6:44 AM, julio cesar oliveira <oliveirajc at ufv.br> wrote:
> Dears,
>
> The arrows command uses the start and end coordinates of each vector, but I
> have the starting coordinates, azimuth, and length.
>
> So, There are package that plot this arrows?
>
> Example:
>
>> x<- c(1,2,4)
>> y<- c(2,3,5)
>> Azimuth<- c(45,90,180)
>> Length<- c(1,0.5,1)
>
>
> Thanks,
>
> Julio
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.



More information about the R-help mailing list