[R] customizing color key with plot3D

Waichler, Scott R Scott.Waichler at pnnl.gov
Wed Jun 21 16:28:40 CEST 2017


Karline,

Thank you for your help.  I discovered that in addition to including clim, I needed to omit breaks.  This code uses one of your other examples as a starting point and works as intended:

persp3D(z = volcano, zlim = c(-60, 200), phi = 20,
        colkey = list(length = 0.2, width = 0.4, shift = 0.15,
        cex.axis = 0.8, cex.clab = 0.85), lighting = TRUE, lphi = 90,
        clab = c("","height","m"), bty = "f", plot = FALSE)
elev.classes <- matrix(findInterval(volcano, vec = seq(50, 200, by=50)), nrow=nrow(volcano), ncol=ncol(volcano))
class.colors <- c("red", "blue", "green")
# add as image with own color key, at bottom
image3D(z = -60, colvar = elev.classes, add = TRUE,
        col = class.colors, #breaks = seq(0.5, 3.5, by=1),
        clim=c(1,3), 
        colkey = list(length = 0.2, width = 0.4, shift = -0.15,
                      cex.axis = 0.8, cex.clab = 0.85, addlines=TRUE, tick=FALSE, 
                      at = c(1.33, 2, 2.66), labels=paste("Class", 1:3)),
        clab = c("","Elev Classes"), plot = TRUE)

Your package plot3D is a huge help to me.  Previously I had to use a completely different software, VisIt, to do these kinds of composite plots.  R is my preferred tool and it is great to finally be able to do these at "home".

Thanks,
Scott Waichler
scott.waichler at pnnl.gov
Pacific Northwest National Laboratory
Richland, Washington, USA

> -----Original Message-----
> From: Karline Soetaert [mailto:Karline.Soetaert at nioz.nl]
> Sent: Wednesday, June 21, 2017 4:16 AM
> To: Waichler, Scott R
> Subject: RE: customizing color key with plot3D
> 
> There is an example in the colkey help file:
> 
> example(colkey)
> 
> will show it ( working on the iris dataset)
> 
> I think the basic thing is that you can use "at"  to position the labels but then
> you also have to specify clim , i.e. "at = c(1.33, 2, 2.66), clim = c(0.5,3.5), col =
> jetc.col(3)...."
> 
> Here is the example:
> 
> with(iris, scatter3D(x = Sepal.Length, y = Sepal.Width,
>     z = Petal.Length, colvar = as.integer(Species),
>    col = c("orange", "green", "lightblue"), pch = 16, cex = 2,
>     clim = c(1, 3), ticktype = "detailed", phi = 20,
>     xlab = "Sepal Length", ylab = "Sepal Width",
>     zlab = "Petal Length",  main = "iris",
>     colkey = list(at = c(1.33, 2, 2.66), side = 1,
>    addlines = TRUE, length = 0.5, width = 0.5,
>    labels = c("setosa", "versicolor", "virginica") )))
> 
> 
> hope it helps,
> 
> 
> Karline
> 
> -----Original Message-----
> From: Waichler, Scott R [mailto:Scott.Waichler at pnnl.gov]
> Sent: woensdag 21 juni 2017 2:01
> To: R. Help <r-help at r-project.org>
> Cc: Karline Soetaert <Karline.Soetaert at nioz.nl>
> Subject: customizing color key with plot3D
> 
> Hi, I am doing composite plots with the package plot3D.  One of my
> variables is qualitative and indexed to integers, and I would like the legend
> for it to have labels located at the integer values (midpoints), and not at the
> breaks between classes.  In the example below, the Elev Classes legend has
> labels at the breaks and nothing at the midpoints.  How can I show the class
> labels at 1:3, and not the breaks?
> 
> library(plot3D)
> persp3D(z = volcano, zlim = c(-60, 200), phi = 20,
>         colkey = list(length = 0.2, width = 0.4, shift = 0.15,
>         cex.axis = 0.8, cex.clab = 0.85), lighting = TRUE, lphi = 90,
>         clab = c("","height","m"), bty = "f", plot = FALSE) # classify the volcano
> elevations with 3 classes elev.classes <- matrix(findInterval(volcano, vec =
> seq(50, 200, by=50)), nrow=nrow(volcano), ncol=ncol(volcano)) class.colors
> <- c("red", "blue", "green") # add as image with own color key, at bottom
> image3D(z = -60, colvar = elev.classes, add = TRUE,
>         col = class.colors, breaks = seq(0.5, 3.5, by=1),
>         colkey = list(length = 0.2, width = 0.4, shift = -0.15,
>                       cex.axis = 0.8, cex.clab = 0.85, addlines=TRUE, tick=FALSE,
>                       at = 1:3, labels=paste("Class", 1:3)),
>         clab = c("","Elev Classes"), plot = TRUE)
> 
> Thanks,
> Scott
> 
> Scott Waichler
> Pacific Northwest National Laboratory
> Richland, Washington, USA
> scott.waichler at pnnl.gov



More information about the R-help mailing list