Re: [R] "Over-coloring" facets on persp() plot

2009-11-23 Thread Duncan Murdoch

On 23/11/2009 8:55 AM, Marc Chiarini (Tufts) wrote:
Thanks Duncan (and David).  I couldn't get back to my computer until 
today.  I understand it pretty well now and I'm able to get what I need.


On a side note, I have had a hard time getting rgl to work.  For the 
moment, I have to compile without libpng and ftfonts, and when I load 
the package I get an error related to OpenGL (from memory, something 
like "no GLX extension found").  I'll write more as soon as I'm able.



You likely need to install OpenGL support on your system.  (It might be 
in MesaGL.)


Duncan Murdoch


Regards,
Marc Chiarini

Duncan Murdoch wrote:

On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote:

Dear R Community:

Recently, I have managed to plot some really useful graphs of my 
research data using persp().  I have even figured out how to overplot 
rectangular regions (corresponding to submatrices) with a different 
color.  This is accomplished by using par(new=T).  I am now searching 
for a way to "highlight" a set of (possibly non-contiguous) facets 
with a specific color, e.g., the facet between each set of four 
points whose values are all above a certain threshold.  An example 
would be coloring the raised corners of the classic sombrero (found 
in example(persp)) differently from the rest of the sombrero.  I feel 
like the last example in persp() is pointing me in the right 
direction, but I'm not quite getting it.  Any help is much appreciated.
Think of the facets as an nx-1 by ny-1 matrix.  Pass the col arg by 
creating a matrix of this shape.  (A vector version of the data in the 
matrix would also be good enough.)


If you pass something shorter, it will be recycled to that length.

You could also use persp3d from the rgl package, but an important 
difference is that it colours all nx by ny vertices, and interpolates 
colours on the facets.  So you can't use the same colour matrix as in 
persp.


Duncan Murdoch



__
R-help@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@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.


Re: [R] "Over-coloring" facets on persp() plot

2009-11-23 Thread Marc Chiarini (Tufts)
Thanks Duncan (and David).  I couldn't get back to my computer until 
today.  I understand it pretty well now and I'm able to get what I need.


On a side note, I have had a hard time getting rgl to work.  For the 
moment, I have to compile without libpng and ftfonts, and when I load 
the package I get an error related to OpenGL (from memory, something 
like "no GLX extension found").  I'll write more as soon as I'm able.


Regards,
Marc Chiarini

Duncan Murdoch wrote:

On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote:

Dear R Community:

Recently, I have managed to plot some really useful graphs of my 
research data using persp().  I have even figured out how to overplot 
rectangular regions (corresponding to submatrices) with a different 
color.  This is accomplished by using par(new=T).  I am now searching 
for a way to "highlight" a set of (possibly non-contiguous) facets 
with a specific color, e.g., the facet between each set of four 
points whose values are all above a certain threshold.  An example 
would be coloring the raised corners of the classic sombrero (found 
in example(persp)) differently from the rest of the sombrero.  I feel 
like the last example in persp() is pointing me in the right 
direction, but I'm not quite getting it.  Any help is much appreciated.


Think of the facets as an nx-1 by ny-1 matrix.  Pass the col arg by 
creating a matrix of this shape.  (A vector version of the data in the 
matrix would also be good enough.)


If you pass something shorter, it will be recycled to that length.

You could also use persp3d from the rgl package, but an important 
difference is that it colours all nx by ny vertices, and interpolates 
colours on the facets.  So you can't use the same colour matrix as in 
persp.


Duncan Murdoch
__
R-help@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.


Re: [R] "Over-coloring" facets on persp() plot

2009-11-22 Thread David Winsemius


On Nov 22, 2009, at 9:18 AM, David Winsemius wrote:



On Nov 22, 2009, at 7:07 AM, Duncan Murdoch wrote:


On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote:

Dear R Community:
Recently, I have managed to plot some really useful graphs of my  
research data using persp().  I have even figured out how to  
overplot rectangular regions (corresponding to submatrices) with a  
different color.  This is accomplished by using par(new=T).  I am  
now searching for a way to "highlight" a set of (possibly non- 
contiguous) facets with a specific color, e.g., the facet between  
each set of four points whose values are all above a certain  
threshold.  An example would be coloring the raised corners of the  
classic sombrero (found in example(persp)) differently from the  
rest of the sombrero.  I feel like the last example in persp() is  
pointing me in the right direction, but I'm not quite getting it.   
Any help is much appreciated.


Think of the facets as an nx-1 by ny-1 matrix.  Pass the col arg by  
creating a matrix of this shape.  (A vector version of the data in  
the matrix would also be good enough.)


I came close to coloring the "top" facet, but did not quite get  
there with:


x <- seq(-10, 10, length= 30)
y <- x
f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
z[is.na(z)] <- 1
op <- par(bg = "white")

zcol <- as.vector( z[-1,-1] == max(z) )  # Need to exclude two side  
edges, I think


persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col =  
ifelse(zcol , "red", "lightblue"),

 ltheta = 120, shade = 0.75, ticktype = "detailed",
 xlab = "X", ylab = "Y", zlab = "Sinc( r )"
)
par(op)

I did not get precisely the top facet in part, because there are 4 z  
elements at the max.


Specifying row and column == 15 for z[-1,-1] does color just the top  
facet. Conditional level coloring can be achieved as above with  
suitable limits on the z values:


zcol <- as.vector( z[-1,-1] >1 & z[-1,-1] <3 )




--
David.




If you pass something shorter, it will be recycled to that length.

You could also use persp3d from the rgl package, but an important  
difference is that it colours all nx by ny vertices, and  
interpolates colours on the facets.  So you can't use the same  
colour matrix as in persp.


Duncan Murdoch

__
R-help@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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


Re: [R] "Over-coloring" facets on persp() plot

2009-11-22 Thread David Winsemius


On Nov 22, 2009, at 7:07 AM, Duncan Murdoch wrote:


On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote:

Dear R Community:
Recently, I have managed to plot some really useful graphs of my  
research data using persp().  I have even figured out how to  
overplot rectangular regions (corresponding to submatrices) with a  
different color.  This is accomplished by using par(new=T).  I am  
now searching for a way to "highlight" a set of (possibly non- 
contiguous) facets with a specific color, e.g., the facet between  
each set of four points whose values are all above a certain  
threshold.  An example would be coloring the raised corners of the  
classic sombrero (found in example(persp)) differently from the  
rest of the sombrero.  I feel like the last example in persp() is  
pointing me in the right direction, but I'm not quite getting it.   
Any help is much appreciated.


Think of the facets as an nx-1 by ny-1 matrix.  Pass the col arg by  
creating a matrix of this shape.  (A vector version of the data in  
the matrix would also be good enough.)


I came close to coloring the "top" facet, but did not quite get there  
with:


x <- seq(-10, 10, length= 30)
y <- x
f <- function(x,y) { r <- sqrt(x^2+y^2); 10 * sin(r)/r }
z <- outer(x, y, f)
z[is.na(z)] <- 1
op <- par(bg = "white")

 zcol <- as.vector( z[-1,-1] == max(z) )  # Need to exclude two  
sides, I think


persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = ifelse(zcol ,  
"red", "lightblue"),

  ltheta = 120, shade = 0.75, ticktype = "detailed",
  xlab = "X", ylab = "Y", zlab = "Sinc( r )"
 )
par(op)

I did not get precisely the top facet in part, because there are 4 z  
elements at the max.


--
David.




If you pass something shorter, it will be recycled to that length.

You could also use persp3d from the rgl package, but an important  
difference is that it colours all nx by ny vertices, and  
interpolates colours on the facets.  So you can't use the same  
colour matrix as in persp.


Duncan Murdoch

__
R-help@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.


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
R-help@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.


Re: [R] "Over-coloring" facets on persp() plot

2009-11-22 Thread Duncan Murdoch

On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote:

Dear R Community:

Recently, I have managed to plot some really useful graphs of my 
research data using persp().  I have even figured out how to overplot 
rectangular regions (corresponding to submatrices) with a different 
color.  This is accomplished by using par(new=T).  I am now searching 
for a way to "highlight" a set of (possibly non-contiguous) facets with 
a specific color, e.g., the facet between each set of four points whose 
values are all above a certain threshold.  An example would be coloring 
the raised corners of the classic sombrero (found in example(persp)) 
differently from the rest of the sombrero.  I feel like the last example 
in persp() is pointing me in the right direction, but I'm not quite 
getting it.  Any help is much appreciated.


Think of the facets as an nx-1 by ny-1 matrix.  Pass the col arg by 
creating a matrix of this shape.  (A vector version of the data in the 
matrix would also be good enough.)


If you pass something shorter, it will be recycled to that length.

You could also use persp3d from the rgl package, but an important 
difference is that it colours all nx by ny vertices, and interpolates 
colours on the facets.  So you can't use the same colour matrix as in persp.


Duncan Murdoch

__
R-help@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] "Over-coloring" facets on persp() plot

2009-11-21 Thread Marc Chiarini (Tufts)

Dear R Community:

Recently, I have managed to plot some really useful graphs of my 
research data using persp().  I have even figured out how to overplot 
rectangular regions (corresponding to submatrices) with a different 
color.  This is accomplished by using par(new=T).  I am now searching 
for a way to "highlight" a set of (possibly non-contiguous) facets with 
a specific color, e.g., the facet between each set of four points whose 
values are all above a certain threshold.  An example would be coloring 
the raised corners of the classic sombrero (found in example(persp)) 
differently from the rest of the sombrero.  I feel like the last example 
in persp() is pointing me in the right direction, but I'm not quite 
getting it.  Any help is much appreciated.


Regards,
Marc

__
R-help@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.