Search code examples
rplotaxis-labelsdensity-plot

How to remove x axis labels in R cdplot?


I would like to remove the default x-axis labels provided by cdplot, and then use the axis() function to introduce my custom labels.

Example

Forest = c(1,0,1,1,1,0,1,1,0,1)
change = c(-1, 3, 1, 4, 1, 1, -1, 1, -1, 6)
mydata = data.frame(Forest,change)

x = factor(mydata$Forest)

cdplot(x~mydata$change, ylab = NA, xlab = NA)

The command xaxt="n" does not work with the cdplot function, while xaxlabels = "n" does not exist at all.

I also tried to use par(xaxt="n") to setup the graphic parameters ex ante, but then prompting the axis(1,...) command does not produce any effect.

Can anyone shed some light about how to procede?

Thanks


Solution

  • Have you tried turning off the axis, plotting, then turning them back on?

    par(xaxt="n")
    cdplot(x~mydata$change, ylab = NA, xlab = NA)
    par(xaxt="s")
    axis(1, ...)