Search code examples
rgraphaxis-labels

R - adjust the y-value of the x axis


I have a some data that I want to display graphically. Here's what it looks like:

data<- c(0.119197746, 0.054207788, 0.895580411, 0.64861727, 0.143249592, 
0.284314897, 0.070027632, 0.297172433, 0.183569184, 0.713896071, 
1.942425326, 1)

Using this command:

barplot(data, main="Ratio of Lipidated and Unlipidated LC3 I & II forms\nNormalized
to GAPDH", names.arg = c("PT250", "PT219", "PT165", "PT218", "PT244", "PT253", "PT279", "PT281",    
"PT240", "PT262", "PT264", "CCD"), ylab = "Fold LC3 II/LC3I/GAPDH")

I produced this graph:

Graph

I would like to position the X-axis at 1 so that all values less-than-one will appear as down bars. I could achieve the desired affect by simply subtracting 1 from all of the values and plotting again but this would cause the numbers on the y-axis to be inaccurate. Is there some way to get R to plot values less than 1 as down bars?


Solution

  • Solution with custom axis.

    barplot(data - 1, main = "Ratio of Lipidated and Unlipidated LC3 I & II forms\nNormalized to GAPDH",
            names.arg = c("PT250", "PT219", "PT165", "PT218", "PT244", "PT253", "PT279", "PT281", "PT240", "PT262", "PT264", "CCD"),
            ylab = "Fold LC3 II/LC3I/GAPDH",
            axes = F,
            ylim = c(-1, 1))
    
    my_labs <- seq(-1, 1, by = 0.5)
    axis(side = 2, at = my_labs, labels = my_labs + 1)
    

    enter image description here