Monday, January 21, 2013

How to make custum labels for the axis in R

If you want to make your own labels for the x- or y- axisdo the following:
Delete the x- or y-axis with xaxt='n', or yaxt='n'.
Then make a vector containing the labels for your axis, e.g.
fold.change <- c("4","3","2","1.5","1.2","all")
Then make the axis:
axis(side = 1, at=1:6, labels = fold.change, tck = -0.02)
side=1 will define the side of the axis, at=1:6 will split the axis into 6 parts, labels=fold.change will put the labels from the vector fold.change, tck=-0.02 will define the orientation and size of the ticks.

The following code will produce the graph bellow.

> plot(x, main="Differentially expressed genes, RN vs KD, p<0.05", xlab="Fold change", ylab="Number of genes", col="red", xaxt='n', type ="b")
> points(y, col="blue", type="b")
> points(z, col="black", type="b")
> points(a, col="orange", type="b")
> fold.change <- c("4","3","2","1.5","1.2","all")
> axis(side = 1, at=1:6, labels = fold.change, tck = -0.02)
> mtext("Upregulated - red, downregulated - black. Filtered with RPKM>1 in blue and orange")

No comments:

Post a Comment