Reputation: 3393
I made a doubleYScale
plot:
library(lattice)
library(latticeExtra)
# Some data
foo <- list(x = 1:100, y = cumsum(rnorm(100)))
obj1 <- xyplot(y~ x, data=foo,xlab=list(cex=1.2),
main="TOtalProduktion VS SummaSkulder/TotaltKapital i procent",
type = c("l","g"),col="black",
lty=1,key = simpleKey(col=c('black'),
text=c("Produktion"),cex=1.2,points=FALSE, lines=TRUE),
scales=list(x=list(rot=90,tick.number=25,
cex=1,axs="r")))
obj2 <- xyplot(y^2 ~ x,data= foo ,type = "o",col="black",
lty=9,key = simpleKey(col=c('black'),
text=c("Summa.skulder"),cex=1.2,lines=FALSE,points= TRUE))
doubleYScale(obj1, obj2, add.ylab2 = TRUE)
The problem
is that I cant manage to change the text size of the y-axic labels (y
and y^2
text, I want to make it larger). It is no problem to change it if I only plot obj1
or obj2
separately, but it doesn't work for doubleYScale
...
I can on the other hand change the size of numbers on the y-axices with:
trellis.par.set(axis.text=list(cex=1))
Any suggestions? I can't manage to find a way :(
Upvotes: 5
Views: 4397
Reputation: 1101
Here is another solution directly with lattice
and latticeExtra
:
where you can set the size of all axis labels independently:
library(lattice)
library(latticeExtra)
foo <- list(x = 1:100, y = cumsum(rnorm(100)))
obj1 <- xyplot(y~ x, data=foo,
xlab=list("Thing", fontsize = 22),
ylab = list("Something", fontsize = 32),
ylab.right = list("Anything", fontsize = 16),
par.settings = simpleTheme(col = 1),
type = c("l","g"),
lty=1,
scales=list(x=list(rot=90,tick.number=25,
cex=1,axs="r")))
obj2 <- xyplot(y^2 ~ x,data= foo ,type = "o",col="black",
lty=9)
doubleYScale(obj1, obj2)
Upvotes: 6
Reputation: 121568
library(grid)
## the text size of the 2 y-axic labels
grid.edit(gPath='GRID.text',grep=T,global=T,gp =gpar(cex=3))
If you want to set different axis sizes
grobs <- sapply(grid.get(gPath='GRID.text',grep=T,global=T),'[')['name',]
grid.edit(gPath=grobs[[1]],gp =gpar(cex=2))
grid.edit(gPath=grobs[[2]],gp =gpar(cex=1.5))
Upvotes: 4
Reputation: 7997
This does not directly answer your question, but mixing two plots of different size on one axis may not be the best approach as it can be misleading. Perhaps a faceted plot using ggplot
would do the job as well or better? All the elements below are easily adjusted.
library(ggplot2)
library(reshape)
set.seed(123)
foo <- list(x = 1:100, y = cumsum(rnorm(100)))
foo <- as.data.frame(foo)
foo$z <- foo$y^2
mymelt <- melt(foo, id.var = 'x')
mymelt$label <- ifelse(mymelt$variable == 'y', "Produktion", "Summa.skulder")
mymelt$line.colour <- ifelse(mymelt$variable == 'y', "red", "blue") # specify colours here
ggplot(data = mymelt, aes(x = x, y = value)) +
geom_line(aes(colour = mymelt$line.colour)) +
facet_wrap(~ label, ncol = 1, scales = "free_y") +
scale_colour_manual(values = unique(mymelt$line.colour)) +
ggtitle("TOtalProduktion VS SummaSkulder/TotaltKapital i procent") +
theme(strip.text.x = element_text(size = 12)) +
theme(axis.text.x = element_text(size = 9)) +
theme(axis.text.y = element_text(size = 9)) +
theme(axis.title.x = element_text(size = 15)) +
theme(axis.title.y = element_text(size = 15)) +
theme(axis.title.x = element_blank()) + # comment out this line if you want an x axis title
theme(axis.title.y = element_blank()) + # comment out this line if you want a y axis title
theme(legend.position = "none")
Upvotes: 3