Hi, Is there any way to add styles to the tick marks in persp() function? For eample I want to add '%' suffix to the z-axis tick marks.in below plot : 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") persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue", ticktype = "detailed") [[alternative HTML version deleted]]
Hi Not in the persp() function itself, but the following code converts the persp() output to 'grid' output then modifies the labels to add percentage signs ... 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") persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue", ticktype = "detailed") library(gridGraphics) grid.echo() labelGrobs <- grid.grep("z-axis-labels", grep=TRUE, global=TRUE) addPercent <- function(x) { lab <- grid.get(x) grid.edit(x, label=paste0(lab$label, "%"), redraw=FALSE) } lapply(labelGrobs, addPercent) grid.refresh() ... is that what you meant? The positioning of the labels relative to the tick marks is imperfect and could perhaps be improved by also editing the 'cex' for the labels, but hopefully this gets close enough to be useful. Paul On 06/08/18 01:04, Christofer Bogaso wrote:> Hi, > > Is there any way to add styles to the tick marks in persp() function? > > For eample I want to add '%' suffix to the z-axis tick marks.in below plot : > > 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") > persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue", > ticktype = "detailed") > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. >-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
Awesome, thanks! On Mon, Aug 6, 2018 at 2:54 AM Paul Murrell <paul at stat.auckland.ac.nz> wrote:> Hi > > Not in the persp() function itself, but the following code converts the > persp() output to 'grid' output then modifies the labels to add > percentage signs ... > > 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") > persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue", > ticktype = "detailed") > > library(gridGraphics) > grid.echo() > labelGrobs <- grid.grep("z-axis-labels", grep=TRUE, global=TRUE) > addPercent <- function(x) { > lab <- grid.get(x) > grid.edit(x, label=paste0(lab$label, "%"), redraw=FALSE) > } > lapply(labelGrobs, addPercent) > grid.refresh() > > ... is that what you meant? The positioning of the labels relative to > the tick marks is imperfect and could perhaps be improved by also > editing the 'cex' for the labels, but hopefully this gets close enough > to be useful. > > Paul > > On 06/08/18 01:04, Christofer Bogaso wrote: > > Hi, > > > > Is there any way to add styles to the tick marks in persp() function? > > > > For eample I want to add '%' suffix to the z-axis tick marks.in below > plot : > > > > 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") > > persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = "lightblue", > > ticktype = "detailed") > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > > > > -- > Dr Paul Murrell > Department of Statistics > The University of Auckland > Private Bag 92019 > Auckland > New Zealand > 64 9 3737599 x85392 > paul at stat.auckland.ac.nz > http://www.stat.auckland.ac.nz/~paul/ >[[alternative HTML version deleted]]
Another possible approach, using the transformation returned by persp() to locate axes explicitly and using base graphics to place labels etc, is given at http://entrenchant.blogspot.com/2014/03/custom-tick-labels-in-r-perspective.html> -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Paul > Murrell > Sent: 05 August 2018 22:24 > To: Christofer Bogaso; r-help > Subject: Re: [R] [FORGED] Adding % sign to ticks in persp() > > Hi > > Not in the persp() function itself, but the following code converts the > persp() output to 'grid' output then modifies the labels to add > percentage signs ... >******************************************************************* This email and any attachments are confidential. Any use...{{dropped:8}}