I want to make a plot in polar coordinates. I want to use pch with shapes that do not have radial symmetry, so I want to rotate them such that they face inwards. I am using grid for my plotting, but I provide motivating examples in graphics. The following plot almost gets me what I want. theta <- 2*pi*seq(0,7/8,1/8) plot(cos(theta), sin(theta), pch=2, axes=F, asp=1) But I want the points to face inwards. I can do something like this with text, but I can set only a constant rotation plot.new() plot.window(c(-1,1),c(-1,1), asp=1) text(cos(theta), sin(theta), 'Tom', srt =runif(1,0,360)) To rotate all of the points, I can do something like this. plot.new() plot.window(c(-1,1),c(-1,1), asp=1) for (the.theta in theta) text(cos(the.theta), sin(the.theta), 'Tom', srt=(360/(2*pi))*(the.theta-(1/4)*2*pi)) So perhaps I could use a "T" instead of a numeric pch and consequently do something like this. plot.new() plot.window(c(-1,1),c(-1,1), asp=1) for (the.theta in theta) text(cos(the.theta), sin(the.theta), 'T', srt=(360/(2*pi))*(the.theta+(1/4)*2*pi)) But that seems a bit silly. Is there a more declarative way of doing this, preferably in grid? Thanks
Silly? Not really. It's simple. It works. You could jump into unicode for your text and make it look nicer, e.g., using '\u2191' or some other shape in place of 'T' http://unicode.org/charts/ http://unicode.org/charts/PDF/U2190.pdf -Dan On Wed, Aug 24, 2016 at 7:16 PM, Thomas Levine <_ at thomaslevine.com> wrote:> I want to make a plot in polar coordinates. I want to use pch with > shapes that do not have radial symmetry, so I want to rotate them such > that they face inwards. I am using grid for my plotting, but I provide > motivating examples in graphics. > > The following plot almost gets me what I want. > > theta <- 2*pi*seq(0,7/8,1/8) > plot(cos(theta), sin(theta), pch=2, axes=F, asp=1) > > But I want the points to face inwards. I can do something like this with > text, but I can set only a constant rotation > > plot.new() > plot.window(c(-1,1),c(-1,1), asp=1) > text(cos(theta), sin(theta), 'Tom', srt > =runif(1,0,360)) > > To rotate all of the points, I can do something like this. > > plot.new() > plot.window(c(-1,1),c(-1,1), asp=1) > for (the.theta in theta) > text(cos(the.theta), sin(the.theta), 'Tom', > srt=(360/(2*pi))*(the.theta-(1/4)*2*pi)) > > So perhaps I could use a "T" instead of a numeric pch and consequently > do something like this. > > plot.new() > plot.window(c(-1,1),c(-1,1), asp=1) > for (the.theta in theta) > text(cos(the.theta), sin(the.theta), 'T', > srt=(360/(2*pi))*(the.theta+(1/4)*2*pi)) > > But that seems a bit silly. > > Is there a more declarative way of doing this, preferably in grid? > > Thanks > > ______________________________________________ > 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. > >-- Dan Dalthorp, PhD USGS Forest and Rangeland Ecosystem Science Center Forest Sciences Lab, Rm 189 3200 SW Jefferson Way Corvallis, OR 97331 ph: 541-750-0953 ddalthorp at usgs.gov [[alternative HTML version deleted]]
Hi Do you mean something like this ... ? library(grid) grid.newpage() pushViewport(viewport(xscale=c(-2,2), yscale=c(-2,2))) grid.text('T', cos(theta), sin(theta), default.units="native", rot=(360/(2*pi))*(theta+(1/4)*2*pi)) Paul On 25/08/16 14:16, Thomas Levine wrote:> I want to make a plot in polar coordinates. I want to use pch with > shapes that do not have radial symmetry, so I want to rotate them such > that they face inwards. I am using grid for my plotting, but I provide > motivating examples in graphics. > > The following plot almost gets me what I want. > > theta <- 2*pi*seq(0,7/8,1/8) > plot(cos(theta), sin(theta), pch=2, axes=F, asp=1) > > But I want the points to face inwards. I can do something like this with > text, but I can set only a constant rotation > > plot.new() > plot.window(c(-1,1),c(-1,1), asp=1) > text(cos(theta), sin(theta), 'Tom', srt > =runif(1,0,360)) > > To rotate all of the points, I can do something like this. > > plot.new() > plot.window(c(-1,1),c(-1,1), asp=1) > for (the.theta in theta) > text(cos(the.theta), sin(the.theta), 'Tom', > srt=(360/(2*pi))*(the.theta-(1/4)*2*pi)) > > So perhaps I could use a "T" instead of a numeric pch and consequently > do something like this. > > plot.new() > plot.window(c(-1,1),c(-1,1), asp=1) > for (the.theta in theta) > text(cos(the.theta), sin(the.theta), 'T', > srt=(360/(2*pi))*(the.theta+(1/4)*2*pi)) > > But that seems a bit silly. > > Is there a more declarative way of doing this, preferably in grid? > > Thanks > > ______________________________________________ > 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. >-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
Well this is great. Now I have answers for both graphics and grid. The rot argument is exactly what I had wanted, except that I had imagined it also working on points. But I had not thought to use unicode, and that will probably make this plot even easier. Thanks