0

I have a simple plot call:

cdplot(example~test)

I would like to make the font of the axes bigger. However,

cdplot(example~test, cex=2.0)

does not work, and I cannot find a solution to this. How do I increase the font size?

2 Answers 2

8

Use the par function to circumvent the problem:

#example data from ?cdplot:
fail <- factor(c(2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1,
                 1, 2, 1, 1, 1, 1, 1),
               levels = 1:2, labels = c("no", "yes"))
temperature <- c(53, 57, 58, 63, 66, 67, 67, 67, 68, 69, 70, 70,
                 70, 70, 72, 73, 75, 75, 76, 76, 78, 79, 81)

#save old parameters
old.par <- par(no.readonly = TRUE)
#change only the size of axis, for axis labels use cex.lab etc, see ?par
par(cex.axis=2)
cdplot(fail ~ temperature)
par(old.par) #restore old parameters

From ?cdplot's arguments section:

bw, n, from, to, ... arguments passed to density.

And from ?density's arguments section:

... further arguments for (non-default) methods.

So you cannot use cdplot(fail ~ temperature,cex.axis=2) because the additional parameters "..." are used by density function which doesn't use them as graphical parameters such as cex.

2
  • Worked perfectly. Thank you so much! Mar 14, 2013 at 7:57
  • 2
    @agstudy of course you are right, par(cex.axis=2) will do it for axis tick labels, par(cex.lab=2) will do it for axis labels? Mar 14, 2013 at 8:08
3

Another alternative is to hack cdplot function , to set cex.axis. But I don't encourage hacking function even is here it is a simple function. Myabe better to contact package maintainer to add axis font feature.

Using getS3method('cdplot','default') you get the function source and you change this line as:

 Axis(xorig, side = 1,cex.axis=cex.x)
 equidist <- any(diff(y1[, 1L]) < tol.ylab)
 if (equidist) 
    axis(2, at = seq.int(1/(2 * ny), 1 - 1/(2 * ny), 
                           by = 1/ny), labels = yaxlabels, tick = FALSE,cex.axis=cex.y)
 else axis(2, at = (y1[-1L, 1L] + y1[-NROW(y1), 1L])/2, 
              labels = yaxlabels, tick = FALSE,cex.axis=cex.y)

I create a new gist with the new function.

For example:

my.cdplot(y=fail ,x=temperature,cex.x=2,cex.y=3)

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.