newbie

Customize plot axes

No votes yet

If you're not happy with what R puts on the axes of your plot (tickmarks, labels etc), plot with "axes=F", then add custom axes with the "axis()" function.

Read more

Grid behind plot

No votes yet

You have a plot, and you want to draw a grid behind it. If you add the grid to the plot, using either

grid()
or
abline()
, the lines will be added on top of your plot, not behind it. I found the solution on the R-help mailing list, here. Redraw the plot after adding the grid, but first set
par(new=T)
so that it will be drawn on top of the old plot on the same device.

Read more

Replace NAs with zeroes

No votes yet

To replace all NA values in an object with zeroes:

x[is.na(x)] <- 0

If you want to do this only for some columns in a matrix or data frame, try this tip, which was posted by John Fox on the R-help mailing list:

cols <- c(1,3)
x[,cols][is.na(x[,cols])] <- 0

If you want to replace the NAs everywhere except in a single column, spare yourself some typing by:

cols <- -3

(then,

x[,cols][is.na(x[,cols])] <- 0
replaces everywhere except in the third column.)

Remove column of data frame by name

No votes yet

x is your data frame. x$total is the column you want to remove:

x$total <- NULL

More at the R Wiki

Syndicate content