Home > Blockchain >  Change baseline y to 1 in barplot (instead of zero)
Change baseline y to 1 in barplot (instead of zero)

Time:10-18

I want to present a barplot with baseline y=1. I want to present fold change, therefore starting with 1. How do I change y starting value with the function barplot? Thanks!

a <- c(0.5,1.5)
barplot(a)

CodePudding user response:

Simulate a new y axis baseline by subtracting 1 and then compensating in the axis labels.

a <- c(0.5,1.5)
at <- c(-0.5, 0, 0.5, 1)

barplot(a - 1, yaxt = "n")
axis(2, at = at, labels = at   1)
abline(h = 0)

Created on 2022-10-17 with enter image description here


Data:

set.seed(334322)
a <- runif(10, 0, 6)

CodePudding user response:

The direct solution is

barplot(a - 1, offset = 1)

enter image description here

Although, being fold changes, consider whether it may be better to use log2 scales or transformations.

  •  Tags:  
  • r
  • Related