Re: [R] Plot Coloured Triangle

From: Greg Snow <Greg.Snow_at_imail.org>
Date: Mon, 09 Jun 2008 09:29:45 -0600

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.
>
______________________________________________ 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.
Received on Mon 09 Jun 2008 - 21:22:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 10 Jun 2008 - 11:30:46 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive