“字体大小”不适用于晶格(R)中的轴和刻度标签

时间:2018-11-06 09:11:12

标签: r lattice

我正在绘制两个带有doubleYscale的xyplot,并对轴的显示方式进行了一些修改。我正在尝试更改所有文本的字体大小,但是“ fontsize”对轴或刻度标签都没有影响。刻度线标签仅适用于“ cex”,而轴标签则不适用,并且这样做会覆盖轴标签。

library(lattice)
library(latticeExtra)
library(grid)

## Sample data
x <- seq(1:10)
y <- x^2
y2 <- x*2

## Prepare list of scales setting that suppresses ticks on top axis
myScales <- list(x = list(tck = c(1,0)))

## Prepare parameter settings, including setting the color used in
## plotting axis line to "transparent"
myTheme <- simpleTheme(col = c("black", "red"),
                   lty = c(1,1))
myTheme <- c(myTheme, list(axis.line = list(col = "transparent")))

myTheme <-c(myTheme, list(par.main.text = list(font = 1, # make it bold
                   just = "left", x = grid::unit(5, "mm"), fontsize=16)), list(axis.text=list(fontsize=16)))

## Write a custom axis function that only plots axis lines on the
## left, right, and bottom sides
myAxisFun <- function(side, line.col, ...) {
if (side == "left") {
    grid.lines(x = c(0, 0), y = c(0, 1),
               default.units = "npc")
} else if (side == "right") {
    grid.lines(x = c(1, 1), y = c(0, 1),
               default.units = "npc")
} else if (side == "bottom") {
    grid.lines(x = c(0, 1), y = c(0, 0),
               default.units = "npc")
}
axis.default(side = side, line.col = "black", ...)
}


## Construct two component plots
plot1 <- xyplot(y ~ x, col="black", type = "l",
            ylab = "Label1", xlab = "",
            par.settings = myTheme,
            scales = myScales,
            axis = myAxisFun,
            main="Title") 
plot2 <- xyplot(y2 ~ x, col="red", type = "l",
            ylab = "Label2", xlab = "",
            par.settings = myTheme,
            scales = myScales,
            axis = myAxisFun)

## Meld the two plots 
doubleYScale(plot1, plot2, add.ylab2 = TRUE)

doubleYscale plot

在axis.text中将“ fontsize = 16”更改为“ cex = 2”(用于说明重叠)

doubleYscale plot 2

0 个答案:

没有答案