[R] Plot Coloured Triangle

Greg Snow Greg.Snow at imail.org
Mon Jun 9 17:29:45 CEST 2008


Here is an example that may get you started:

point1 <- c(1.1, 1.7, 255)
point2 <- c(2.2, 1.5, 180)
point3 <- c(1.8, 2.2, 60)

mydf <- as.data.frame( rbind(point1, point2, point3) )
names(mydf) <- c('x1','x2','red')

fit <- lm(red~x1+x2, data=mydf)

df2 <- expand.grid( x1=seq(min(mydf$x1), max(mydf$x1), length=250),
        x2=seq(min(mydf$x2), max(mydf$x2), length=250) )

df2$red <- predict(fit, df2)

library(sp)
tmp <- point.in.polygon( df2$x1, df2$x2, mydf$x1, mydf$x2)

df2$red[ tmp==0 ] <- NA

reds <- sort(unique(df2$red))
cols <- rgb(reds, 0, 0, maxColorValue=255)

library(lattice)
levelplot( red~x1+x2, data=df2, col.regions=cols )


--
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 Antje
> Sent: Monday, June 09, 2008 2:57 AM
> To: r-help at stat.math.ethz.ch
> Subject: [R] Plot Coloured Triangle
>
> Hi there,
>
> I'd like to plot a triangle with each point having a certain
> color defined and fill it with the interpolated values.
> The following code shall represent somehow, three points with
> x,y, and the "amount" of red for example...
>
> point1 <- c(1.1, 1.7, 255)
> point2 <- c(2.2, 1.5, 180)
> point3 <- c(1.8, 2.2, 60)
>
> can anybody give me a hint which methods to use to realize it?
>
> Antje
>
> ______________________________________________
> 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