[R] plotting points with two colors

Greg Snow Greg.Snow at imail.org
Tue Jan 20 19:04:46 CET 2009


I don't know how efficient you would consider this, but here is one solution:

library(TeachingDemos)

ms.2circ <- function(r=1, adj=0, col1='blue', col2='red', npts=180) {
	tmp1 <- seq( 0,   pi, length.out=npts+1) + adj
	tmp2 <- seq(pi, 2*pi, length.out=npts+1) + adj
	polygon(cos(tmp1)*r,sin(tmp1)*r, border=NA, col=col1)
	polygon(cos(tmp2)*r,sin(tmp2)*r, border=NA, col=col2)
	invisible(NULL)
}

x <- runif(10)
y <- rnorm(10)
a <- runif(10, 0, 2*pi)

my.symbols(x,y, ms.2circ, inches=0.15, add=FALSE, symb.plots=TRUE, adj=a)

# or

my.symbols(x,y, ms.2circ, inches=0.15, add=FALSE, symb.plots=TRUE, adj=a,
	col1="#00ff0088", col2="#ff00ff88")

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Georg Ehret
> Sent: Tuesday, January 20, 2009 10:23 AM
> To: r-help
> Subject: [R] plotting points with two colors
> 
> Dear Miss R,
>     I am trying to plot a scatterplot in which the points (round)
> should
> have two colors: half red and half blue (if you want: two half solid
> circles
> put together. Can you please help me to realize this efficiently?
> 
> Thank you,
> Best regards, Georg.
> ***************************************
> Georg Ehret
> Geneva University Hospital
> Geneva, Switzerland
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.




More information about the R-help mailing list