[R] [FORGED] Re: draw stripes in a circle in R

Jim Lemon drjimlemon at gmail.com
Thu Jun 15 00:22:43 CEST 2017


Hi Jean-Phillipe,
Thanks for the plug on plotrix. Because of that I will suggest a gross
hack that will do almost what you want:

# your code down to draw.circle
segments(c(-12.7,-12.7),c(-11.2,-10.6),c(-12,-12),
 c(-10.75,-10.15),col="white",lwd=28)
draw.circle(-12.85,-10.9,0.85,nv=1000,border=NULL,
col=NA,lty=1,lwd=1)
box()
dev.off()

Your problem is that plotrix is written in base graphics, which is
simple to understand, but does not support layered graphics. Thus I
have to do the striping over the yellow circle and avoid overwriting
the big red stripe. You should do this using the grid graphic system,
but that would take too large a chunk of my morning to write an
example for you.

To Rolf - It happened to me as well, but because I saw Venus smiling
at me in the sky this morning I was granted the knowledge that it was
a function that had not been properly introduced to us and simply
replaced it with "red". Such are the benefits of evidence-based
astrology.

Jim


On Thu, Jun 15, 2017 at 8:04 AM, jeanphilippe.fontaine
<jeanphilippe.fontaine at gssi.infn.it> wrote:
>
>
>
>
>
>
> Envoyé depuis mon appareil Samsung
>
> -------- Message d'origine --------
> De : Rolf Turner <r.turner at auckland.ac.nz>
> Date : 14/06/2017  22:53  (GMT+01:00)
> À : David Winsemius <dwinsemius at comcast.net>
> Cc : r-help at r-project.org
> Objet : Re: [R] [FORGED] Re:  draw stripes in a circle in R
>
> On 15/06/17 05:29, David Winsemius wrote:
>>
>>> On Jun 14, 2017, at 10:18 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>>>
>>>
>>>> On Jun 14, 2017, at 9:46 AM, Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote:
>>>>
>>>> I don't see a question. If your question is whether R supports pattern fills, AFAIK it does not. If that is not your question, ask one.
>>>> --
>>>> Sent from my phone. Please excuse my brevity.
>>>>
>>>> On June 14, 2017 7:57:41 AM PDT, jean-philippe <jeanphilippe.fontaine at gssi.infn.it> wrote:
>>>>> dear R users,
>>>>>
>>>>> I would like to fill a circle with yellow stripes instead of a uniform
>>>>> yellow color. To draw the circle I used the following command after
>>>>> having loaded the (very nice !) plotrix library :
>>
>> I finally understood the question and it needs a hack to the draw.circle function in plotrix since the angle and density arguments don't get passed in:
>>
>> First get code for draw.circle:
>>
>> ------
>>
>> draw.circle   # then copy to console and edit
>>
>> draw.circle2  <- function (x, y, radius, nv = 100, border = NULL, col = NA, lty = 1,
>>                             density=NA, angle=45,  lwd = 1 )
>> {
>>      xylim <- par("usr")
>>      plotdim <- par("pin")
>>      ymult <- getYmult()
>>      angle.inc <- 2 * pi/nv
>>      angles <- seq(0, 2 * pi - angle.inc, by = angle.inc)
>>      if (length(col) < length(radius))
>>          col <- rep(col, length.out = length(radius))
>>      for (circle in 1:length(radius)) {
>>          xv <- cos(angles) * radius[circle] + x
>>          yv <- sin(angles) * radius[circle] * ymult + y
>>          polygon(xv, yv, border = border, col = col, lty = lty, density=density, angle=angle,
>>                  lwd = lwd)
>>      }
>>      invisible(list(x = xv, y = yv))
>> }
>>
>> Now run your call to pdf with draw.circle2 instead of draw.circle.
>
> This is just idle curiosity, since I'm not really able to contribute
> anything useful, but I can't resist asking:  When I try to run the OP's
> code I get an error:
>
>> Error in alpha("red", 0.4) : could not find function "alpha".
>
> Sorry for the lack of precision, alpha is just to add some transparency to the color. This alpha parameter ranges from 0 fully transparent to 1, full color.I don't remember having loaded any package to use this function, I think it is there in base R.
> Why does this (apparently) not happen to anyone else?  Why does the
> universe pick on *me*?  What is the function "alpha()"?  Where is it to
> be found?
>
> Searching on "alpha" is of course completely unproductive; there are far
> too many (totally irrelevant) instances.
>
> cheers,
>
> Rolf
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> ______________________________________________
> 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.
>
>         [[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