I am using grid()
inside of barplot()
. Because I want the bars to be plotted on top of the grid, I use the panel.first
argument. However, the grid lines do not match the ticks of y-axis. Can anyone tell me how to solve this problem? My code is like below, thanks.
WRE <- c(1423, 41721)
bp <- barplot(WRE, xaxt = 'n', xlab = '', yaxt = 'n', las = 3, width = 0.5,
space = 1.5, main = paste("How You Compare", sep = ""), ylab = "",
names.arg = NA, col = c("red","blue"), cex.lab = 1,
panel.first = grid(nx = NA, ny = NULL))
axis(1, at=bp, labels=c("Average Claims", "Your Claims"),
tick=FALSE, las=1, line=-1, cex.axis=1)
axis(2, at=axTicks(2), sprintf("$%s", formatC(axTicks(2), digits=9, big.mark=",", width=-1)),
cex.axis=0.9, las=2)