Skip to content

polygon angle option perpendicular to axis

7 messages · Simon, Heather, Peter Alspach, Greg Snow +2 more

#
I am trying to use the angle option in polygon to create polygons filled with horizontal and vertical lines.  The polygons I am crating are irregular and it the angle function appears to set the angle of the shading perpendicular to the polygon sides rather than perpendicular to the axes.  Is there any way to set the angle relative to the axes rather than relative to the polygon sides?
#
Tena koe Simon

plot(1:10, 1:10, type='n')
polygon(c(2,3,6,8), c(2,5,5,3), density=20, angle=90)
polygon(c(2,3,6,8), 5+c(2,5,5,3), density=20, angle=0)

I don't understand your problem.  Perhaps if you "provide[d] commented, minimal, self-contained, reproducible code" it would help.

HTH ....

Peter Alspach

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Simon, Heather
Sent: Thursday, 28 April 2016 8:17 a.m.
To: r-help at r-project.org
Subject: [R] polygon angle option perpendicular to axis

I am trying to use the angle option in polygon to create polygons filled with horizontal and vertical lines.  The polygons I am crating are irregular and it the angle function appears to set the angle of the shading perpendicular to the polygon sides rather than perpendicular to the axes.  Is there any way to set the angle relative to the axes rather than relative to the polygon sides?




______________________________________________
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.
The contents of this e-mail are confidential and may be ...{{dropped:14}}
#
Thanks for the question.  Here is a sample of the code for my plot:

	Top = c(34, 39, 42, 45, 46, 41, 41, 40, 43, 38, 33, 33)
	 Bottom = c(24, 29, 32, 36, 32, 34, 32,41, 40, 39, 29, 24)

	plot(1,1, col = "white", xlim = c(1.3,11.7), ylim = c(0,80), axis = FALSE, xaxt = "n") 
	axis(1, at = c(1:12))

	polygon(c(c(1:12),c(12:1)), c(top, bottom), col = adjustcolor("#33a02c",alpha.f = 0.7) ,border = "#33a02c", lty = 4, density = 80, angle = 180)


I would like the hatched lines to all go in the same direction (parallel to the x-axis) so that I can layer another polygon on top with perpendicular hatches and you will be able to differentiate between the two.

-----Original Message-----
From: Peter Alspach [mailto:Peter.Alspach at plantandfood.co.nz] 
Sent: Thursday, April 28, 2016 12:11 AM
To: Simon, Heather <Simon.Heather at epa.gov>; r-help at r-project.org
Subject: RE: polygon angle option perpendicular to axis

Tena koe Simon

plot(1:10, 1:10, type='n')
polygon(c(2,3,6,8), c(2,5,5,3), density=20, angle=90) polygon(c(2,3,6,8), 5+c(2,5,5,3), density=20, angle=0)

I don't understand your problem.  Perhaps if you "provide[d] commented, minimal, self-contained, reproducible code" it would help.

HTH ....

Peter Alspach

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Simon, Heather
Sent: Thursday, 28 April 2016 8:17 a.m.
To: r-help at r-project.org
Subject: [R] polygon angle option perpendicular to axis

I am trying to use the angle option in polygon to create polygons filled with horizontal and vertical lines.  The polygons I am crating are irregular and it the angle function appears to set the angle of the shading perpendicular to the polygon sides rather than perpendicular to the axes.  Is there any way to set the angle relative to the axes rather than relative to the polygon sides?




______________________________________________
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.
The contents of this e-mail are confidential and may be ...{{dropped:9}}
#
Filling polygons with lines is a throwback to the time when the height
of quality graphics was the mechanical pen plotter (a device that used
a pen in a mechanical arm to draw the plot on a piece of paper).
Computing and printing technology has advanced quite a bit from that
day, so you may want to reconsider why you want polygons filled with
lines instead of just a solid color (and I consider white, grey, and
black as colors for this purpose).
On Wed, Apr 27, 2016 at 2:17 PM, Simon, Heather <Simon.Heather at epa.gov> wrote:

  
    
#
I think you are seeing the Moire (interference) pattern arising from
the interaction of lty=4 (dotted/dashed lines) and closely spaced
parallel lines.  Use lty=1 (solid lines) to see this.

[BTW, your script did not work because you changed the capitalization
of top and bottom halfway through it.]

As for hatching being old-fashioned, when I read stats stuff on my
black and white Kindle I wish that people used color less and hatching
more.


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Apr 28, 2016 at 5:45 AM, Simon, Heather <Simon.Heather at epa.gov>
wrote:

  
  
#
The angle is not based on the polygon edges, but it can seem that way if you do not use the asp=1 argument in your plot. Try this example,
Notice that the 45 and 135 degree lines (upper left and lower right) do not seem to be parallel to the edges of the boxes which should be 45 and 135. Run the code again adding asp=1 to the plot() function and now the lines are parallel.

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

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Greg Snow
Sent: Thursday, April 28, 2016 9:50 AM
To: Simon, Heather
Cc: r-help at r-project.org
Subject: Re: [R] polygon angle option perpendicular to axis

Filling polygons with lines is a throwback to the time when the height
of quality graphics was the mechanical pen plotter (a device that used
a pen in a mechanical arm to draw the plot on a piece of paper).
Computing and printing technology has advanced quite a bit from that
day, so you may want to reconsider why you want polygons filled with
lines instead of just a solid color (and I consider white, grey, and
black as colors for this purpose).
On Wed, Apr 27, 2016 at 2:17 PM, Simon, Heather <Simon.Heather at epa.gov> wrote:

  
    
#
Thanks, adding asp = 1 did the trick!

-----Original Message-----
From: David L Carlson [mailto:dcarlson at tamu.edu] 
Sent: Thursday, April 28, 2016 12:17 PM
To: Greg Snow <538280 at gmail.com>; Simon, Heather <Simon.Heather at epa.gov>
Cc: r-help at r-project.org
Subject: RE: [R] polygon angle option perpendicular to axis

The angle is not based on the polygon edges, but it can seem that way if you do not use the asp=1 argument in your plot. Try this example,
Notice that the 45 and 135 degree lines (upper left and lower right) do not seem to be parallel to the edges of the boxes which should be 45 and 135. Run the code again adding asp=1 to the plot() function and now the lines are parallel.

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

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Greg Snow
Sent: Thursday, April 28, 2016 9:50 AM
To: Simon, Heather
Cc: r-help at r-project.org
Subject: Re: [R] polygon angle option perpendicular to axis

Filling polygons with lines is a throwback to the time when the height of quality graphics was the mechanical pen plotter (a device that used a pen in a mechanical arm to draw the plot on a piece of paper).
Computing and printing technology has advanced quite a bit from that day, so you may want to reconsider why you want polygons filled with lines instead of just a solid color (and I consider white, grey, and black as colors for this purpose).
On Wed, Apr 27, 2016 at 2:17 PM, Simon, Heather <Simon.Heather at epa.gov> wrote:
--
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com

______________________________________________
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.