alan
2012-Mar-28 02:49 UTC
[R] plot points using circles filled half in red and half in blue.
I want to plot many points and want to use circles. The filling color depends on variable a. if a=1, then not fill if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill half with red and half with blue. Can anyone tell me how to plot the case "a=4"? Thanks a lot
Rolf Turner
2012-Mar-28 09:06 UTC
[R] plot points using circles filled half in red and half in blue.
On 28/03/12 15:49, alan wrote:> I want to plot many points and want to use circles. The filling color > depends on variable a. if a=1, then not fill > if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill > half with red and half with blue. Can anyone tell me how to plot the > case "a=4"? Thanks a lotI could be wrong --- this was known to happen once :-) --- but I strongly doubt that there is anything ``off the peg'' that will do what you want. You'll have to roll your own. I'd suggest looking at the draw.circle() function from the plotrix package for some ideas on how to get started. It seems to me that for each such circle you'll have to plot two polygons --- one for each half of the circle --- and specify fill="red" for one and fill="blue" for the other. It's all do-able, but is it worth the effort? Why not fill with green (say) when a=4? cheers, Rolf Turner
Eik Vettorazzi
2012-Mar-28 10:02 UTC
[R] plot points using circles filled half in red and half in blue.
Hi Alan, on an UTF-8 locale you can use \u25D6 and \u25D7, but you have to plot group a=4 twice. On Windows in a non-utf locale you can use a special Windows font: windowsFonts(wdg2=windowsFont("Wingdings 2")) plot(0:1,0:1) strh<-strheight("x")/2.02 points(x = 0.5, y = 0.75+strh/2,pch="?",family="wdg2",col="red") points(x = 0.5, y = 0.75-strh/2,pch="?",family="wdg2",col="green") strw<-strwidth("?") points(.4-strw/2,.7,pch="?",family="wdg2",col="red") points(.4+strw/2,.7,pch="?",family="wdg2",col="green") Cheers Am 28.03.2012 04:49, schrieb alan:> I want to plot many points and want to use circles. The filling color > depends on variable a. if a=1, then not fill > if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill > half with red and half with blue. Can anyone tell me how to plot the > case "a=4"? Thanks a lot > > ______________________________________________ > R-help at r-project.org mailing list > 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.-- Eik Vettorazzi Department of Medical Biometry and Epidemiology University Medical Center Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gem?? Gesetz ?ber elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universit?tsklinikum Hamburg-Eppendorf; K?rperschaft des ?ffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Pr?l?, Prof. Dr. Dr. Uwe Koch-Gromus
Gabor Grothendieck
2012-Mar-28 11:28 UTC
[R] plot points using circles filled half in red and half in blue.
On Tue, Mar 27, 2012 at 10:49 PM, alan <alan.wu2007 at gmail.com> wrote:> I want to plot many points and want to use circles. The filling color > depends on variable a. if a=1, then not fill > if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill > half with red and half with blue. Can anyone tell me how to plot the > case "a=4"? Thanks a lot >There is an example in the vignette that comes with the gridBase package of having a pie chart for each point. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
Greg Snow
2012-Mar-28 20:59 UTC
[R] plot points using circles filled half in red and half in blue.
I would use the my.symbols function from the TeachingDemos package (but then I might be a little bit biased), here is a simple example: library(TeachingDemos) x <- runif(25) y <- runif(25) z <- sample(1:4, 25, TRUE) ms.halfcirc2 <- function(col, adj=pi/2, ...) { theta <- seq(0, 2*pi, length.out=300)+adj x <- cos(theta) y <- sin(theta) if(col==1) { polygon(x,y) } else if(col==2) { polygon(x,y, col='red') } else if(col==3) { polygon(x,y, col='blue') } else { polygon(x[1:150], y[1:150], border=NA, col='red') polygon(x[151:300], y[151:300], border=NA, col='blue') polygon(x,y) } } my.symbols( x, y, ms.halfcirc2, inches=1/5, add=FALSE, symb.plots=TRUE, col=z) # spice it up a bit my.symbols( x, y, ms.halfcirc2, inches=1/5, add=FALSE, symb.plots=TRUE, col=z, adj=runif(25, 0, pi)) Adjust things to fit better what you want. On Tue, Mar 27, 2012 at 8:49 PM, alan <alan.wu2007 at gmail.com> wrote:> I want to plot many points and want to use circles. The filling color > depends on variable a. if a=1, then not fill > if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill > half with red and half with blue. Can anyone tell me how to plot the > case "a=4"? Thanks a lot > > ______________________________________________ > R-help at r-project.org mailing list > 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
Jim Lemon
2012-Mar-31 09:53 UTC
[R] plot points using circles filled half in red and half in blue.
On 03/28/2012 01:49 PM, alan wrote:> I want to plot many points and want to use circles. The filling color > depends on variable a. if a=1, then not fill > if a=2 then fill with red, if a=3 then fill with blue, if a=4, fill > half with red and half with blue. Can anyone tell me how to plot the > case "a=4"? Thanks a lot >Hi alan, I think you can do this with the "floating.pie" function (plotrix). Just plot two equal numbers and the "pie" will be two half circles. Jim