[R] draw stripes in a circle in R
jean-philippe
jeanphilippe.fontaine at gssi.infn.it
Thu Jun 15 10:35:19 CEST 2017
hi david
Thank you very much for the hack of draw.circle that you proposed me.
I don't understand some part of the code, why do you pass radius as a
vector in the function (if I understand well the purpose of the for
loop) ? Also what is ymult?
If I set the radius to the value 0.85 as I wanted (so as a scalar), I
don't see any difference in the result when I call this function
draw.circle2, the stripes are not drawn inside the circle. I don't know
if it is normal.
Thanks, best
Jean-Philippe
On 14/06/2017 19: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
>
> Best;
> David.
>>>> library(plotrix)
>>>> pdf("MWE.pdf",width=8, height=8)
>>>> plot(seq(-12.5,-8.7,length.out=100),seq(-11.3,-8.3,length.out=100),type="l",col="red",xlim=c(-12.5,-8.7),ylim=c(-11.5,-8.5))
>>>> par(new=T)
>>>> plot(seq(-12.5,-8.7,length.out=100),seq(-11.7,-8.7,length.out=100),type="l",col="red",xlim=c(-12.5,-8.7),ylim=c(-11.5,-8.5))
>>>> par(new=T)
>>>> polygon(c(seq(-12.5,-8.7,length.out=100),
>>>> rev(seq(-12.5,-8.7,length.out=100))), c(seq(-11.3,-8.3,length.out=100),
>>>>
>>>> rev(seq(-11.7,-8.7,length.out=100))),
>>>> col = alpha("red",0.4), border = NA)
>>>> par(new=T)
>>>> draw.circle(-12.85,-10.9,0.85,nv=1000,border=NULL,col="yellow",lty=1,lwd=1)
>>>> dev.off()
>>>>
>> Agree that the coding question remains unclear, so not using the offered example but responding to the natural language query. The `polygon` function has 'density' and 'angle' argument that with 'col' and 'lwd' can make slanted fill lines. This is a modification of hte first example on `?polygon`?
>>
>> x <- c(1:9, 8:1)
>> y <- c(1, 2*(5:3), 2, -1, 17, 9, 8, 2:9)
>> op <- par(mfcol = c(3, 1))
>> for(xpd in c(FALSE, TRUE, NA)) {
>> plot(1:10, main = paste("xpd =", xpd))
>> box("figure", col = "pink", lwd = 3)
>> polygon(x, y, xpd = xpd, col = "orange", density=3, angle=45, lwd = 5, border = "red")
>> }
>>
>> The polygon function is _not_ in pkg::plotrix.
>>
>>
>>
>>>> It looks a bit ugly since they are not real data, but it is the
>>>> simplest
>>>> MWE example that I found.
>>>>
>>>>
>>>> Thanks, best
>>>>
>>>>
>>>> Jean-Philippe
>>> ______________________________________________
>>> 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.
>> David Winsemius
>> Alameda, CA, USA
>>
>> ______________________________________________
>> 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.
> David Winsemius
> Alameda, CA, USA
>
> ______________________________________________
> 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.
--
Jean-Philippe Fontaine
PhD Student in Astroparticle Physics,
Gran Sasso Science Institute (GSSI),
Viale Francesco Crispi 7,
67100 L'Aquila, Italy
Mobile: +393487128593, +33615653774
More information about the R-help
mailing list