Not sure why it didn't work for you. I've taken the liberty to reformat your code, other than that nothing important has changed. Anyway, here's the plot:
EDIT: The problem seems to be related to the settings of lattice (see ?trellis.par.get
). I've updated the source accordingly, that should solve the problem.
And here's the source:
library(lattice)
library(latticeExtra)
# xx <- ... paste your dataset here
# Adapt these to your needs:
parSettings <- list(layout.widths=list(left.padding=5))
#First graph
comma_formatter <- function (lim, logsc = FALSE, at = NULL, ...) {
ans <- yscale.components.default(lim = lim, logsc = logsc, at = at, ...)
xxPrime <- as.numeric(ans$left$labels$labels)
ans$left$labels$labels <- formatC(xxPrime, format = "fg", big.mark = ",")
ans
}
#Plot
DD <- barchart(a1 ~ a5, xx, yscale.components = comma_formatter, par.settings = parSettings)
#Second graph
percent <- function (lim, logsc = FALSE, at = NULL, ...) {
# Helper function (never needed elsewhere, so we can declare it here)
percent1 <- function(x, digits = 2, format = "f", ...)
paste(formatC(100 * x, format = format, digits = digits, ...), "%", sep = "")
ans <- yscale.components.default(lim = lim, logsc = logsc, at = at, ...)
xxPrime <- as.numeric(ans$left$labels$labels)
ans$left$labels$labels <- percent1(xxPrime)
ans
}
#Plot
D3 <- xyplot(a3+a4 ~ a5, xx, type = "b", yscale.components = percent, par.settings = parSettings)
#Final graph
DF <- doubleYScale(DD, D3, style1 = 3, style2 = 0, add.ylab2 = FALSE,
text = c("a3", "a4", "a1"), main = "Nuevo Gráfico")
plot(DF)