yy <- c(4,6,13,24,15,13,14,8,2,1)
n <- length(yy)
bar <- data.frame(Group=LETTERS[1:n], value=yy*1000, yield=yy+rnorm(n,50,10))
ylim <- c(0,max(bar$value))
space <- 0.3
xlim <- c(0, floor((1+space)*n)+1)
plot(0, xaxs = "i", xlim = xlim, ylim = ylim, main = "Barplot with Line use par(new=TRUE)", xlab = "", ylab = "", type = "n", axes = FALSE)
r <- barplot(bar$value, axes=F, axisnames = FALSE, space = space, add = T)
axis(1, at = r, labels = LETTERS[1:n])
axis(2, at = seq(0,ylim[2], 1000), las = 2)
#use par new
par(new = TRUE)
plot(x = r, y = bar$yield, axes = FALSE, xlim = xlim, ylim = c(0,110) ,xlab = "", ylab = "",type = "o")
abline(v=r, lty = 2, col = "red")
axis(4, at = seq(0, 110, 10))
box()

plot(0, xaxs = "i", xlim = xlim, ylim = ylim, main = "Barplot with Line use updateusr", xlab = "", ylab = "", type = "n", axes = FALSE)
r <- barplot(bar$value, axes=F, axisnames = FALSE, space = space, add = T)
axis(1, at = r, labels = LETTERS[1:n])
axis(2, at = seq(0,ylim[2], 1000), las = 2)
#By using updateusr
updateusr(r[1:2], ylim/100, r[1:2], 0:1)
lines(x = r, y = bar$yield, type = "o")
abline(v=r, lty = 2, col = "red")
axis(4, at = seq(0, 110, 10))
box()