Hi,
thank you very much for your help, but I need something different.

For example, I wrote this code to highlight the standard deviation area 
of each distribution

fn <- function(x, y, scale, scale2)
dnorm(x,mean=1,sd=scale)*dnorm(y,mean=-1,sd=scale) +
dnorm(x,mean=2,sd=scale2)*dnorm(y,mean=1,sd=scale) +
dnorm(x,mean=-3,sd=scale)*dnorm(y,mean=1,sd=scale2)

x <- seq(-4,4,len=40)
y <- seq(-4,4,len=40)
z <- outer(x, y, fn, scale = 1, scale2 = 0.5)
nrz <- nrow(z)
ncz <- ncol(z)
jet.colors <- colorRampPalette( c("lightblue", "yellow") )
nbcol <- 100
color <- jet.colors(nbcol)
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)

phi <- seq(0, 2*pi, len = 201)

#postscript ("3d-gaussian.eps", family = "Times", paper="special", 
horizontal=FALSE, width=15/2.54, height=15/2.54, pointsize=8)
res <- persp(x,y,z, theta = 30, phi = 30, expand = 0.2, col = 
color[facetcol],
       ltheta = 120, shade = 0.75, ticktype = "detailed")

polygon(trans3d(1+(1*cos(phi)), -1+(1*sin(phi)), fn(1, -1, 1, 0.5), pmat 
= res), col = rgb(1,0,0,0.5), border = NA)
lines(trans3d(1+(1*cos(phi)), -1+(1*sin(phi)), fn(1, -1, 1, 0.5), pmat = 
res), col = "black", lwd = 1, lty = 2)

polygon(trans3d(2+(0.5*cos(phi)), 1+(1*sin(phi)), fn(2, 1, 1, 0.5), pmat 
= res), col = rgb(0,1,0,0.5), border = NA)
lines(trans3d(2+(0.5*cos(phi)), 1+(1*sin(phi)), fn(2, 1, 1, 0.5), pmat = 
res), col = "black", lwd = 1, lty = 2)

polygon(trans3d(-3+(1*cos(phi)), 1+(0.5*sin(phi)), fn(-3, 1, 1, 0.5), 
pmat = res), col = rgb(0,0,1,0.5), border = NA)
lines(trans3d(-3+(1*cos(phi)), 1+(0.5*sin(phi)), fn(-3, 1, 1, 0.5), pmat 
= res), col = "black", lwd = 1, lty = 2)
#dev.off()

... but the result is still not so good!!

Best,
Roberto


Il 26/12/2012 20:41, David Winsemius [via R] ha scritto:
>
> On Dec 25, 2012, at 11:58 PM, Roberto wrote:
>
> > I wrote, finding pieces of code in the web, a simple script to draw
> > a 3D
> > gaussian plot.
>
> > For the next step, I need that the 2 gaussian distributions have
> > different
> > colors.
> >
> > Can someone help me to do this?
> >
> > fn <- function(x, y, scale, scale2)
> > dnorm(x,mean=1,sd=scale)*dnorm(y,mean=-1,sd=scale) +
> > dnorm(x,mean=2,sd=scale2)*dnorm(y,mean=1,sd=scale2)
> >
> > x <- seq(-4,4,len=40)
> > y <- seq(-4,4,len=40)
> > z <- outer(x, y, fn, scale = 1, scale2 = 0.5)
> > nrz <- nrow(z)
> > ncz <- ncol(z)
> > jet.colors <- colorRampPalette( c("lightblue", "green", "darkgreen") )
> > nbcol <- 100
> > color <- jet.colors(nbcol)
> > zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
> > # Recode facet z-values into color indices
> > facetcol <- cut(zfacet, nbcol)
> > persp(x,y,z, theta = 30, phi = 30, expand = 0.2, col =
> > color[facetcol],
> >      ltheta = 120, shade = 0.75, ticktype = "detailed")
>
> There really is no specific division since both distributions
> contribute something at each point, so I took this to mean that you
> wanted something that might arise in an effort to divide the plane
> into two regions where their contributions were greatest. This effort
> was done by eyeball:
>
> persp(x,y,z, theta = 30, phi = 30, expand = 0.2, col = c("blue", "red")
> [1+(row(z[-1,-1])+col(z[-1,-1]) <= 47)],
>       ltheta = 120, shade = 0.75, ticktype = "detailed")
>
>
> Need to construct an index matrix to the color vector that matches the
> dimensions of the facets which are one less than the dimensions of z
> (adding 1 since R indices need to start at 1 and logical FALSE is 0) .
> This constructs a matrix of conditions based on
>
> David Winsemius, MD
> Alameda, CA, USA
>
> ______________________________________________
> [hidden email] </user/SendEmail.jtp?type=node&node=4653978&i=0> 
> 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.
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the 
> discussion below:
> http://r.789695.n4.nabble.com/3D-Gaussian-with-different-colors-tp4653938p4653978.html 
>
> To unsubscribe from 3D Gaussian with different colors, click here 
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4653938&code=cm1vc2NldHRpQHVuaXR1cy5pdHw0NjUzOTM4fC01NTAwNjYxNDc=>.
> NAML 
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> 
>


-- 
Roberto Moscetti
PhD Student
University of Tuscia
Viterbo, Italy
----------------
Mobile +39 346 8041267
Phone  +39 0761 357415





--
View this message in context: http://r.789695.n4.nabble.com/3D-Gaussian-with-different-colors-tp4653938p4654052.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]


