I'm trying to create a barplot combined with line plots, but I have troubles centering all graphs, so it match the x-axis. I want the bar labels (had to censor them ;) ) and points of both line plots centered with the x-axis ticks.
I don't really get why the x-axis ticks are correctly centered with bars, but everything else is dis-centered in such strange way (although I'm using the same variable x to position both of them).
How can I center them all together.
Here is the code that I have made for plotting (the image it produces is below):
#### base sytem
par(mar = rep(4, 4))
barData <- con
y <- lineData <- CPL
z <- CPLmax
x <- barplot(barData,
axes = FALSE,
col = "green",
xlab = "",
ylab = "",
ylim = c(0, max(con) * 1.1))
axis(1, at = x, labels = timeline)
axis(4, at = NULL)
par(new = TRUE)
plot(x = x, y = y, type = "b", col = "blue", axes = FALSE, xlab = "", ylab = "", ylim = c(0, max(CPL) * 1.1))
lines(x = x, y = z, type = "b", col = "red", axes = FALSE, ylab = "", ylim = c(0, max(CPL) * 1.1))
axis(2, at = NULL)
text(x = x, y = 3, labels = barData, pos = 1 )
abline(v= x, col="purple")
print(x)
print(y)
box()