如何在R中均匀地完全缩放晶格xyplot?

时间:2016-10-27 08:05:22

标签: r lattice

我需要制作一个格子xyplot并将其装入8厘米x 8厘米的pdf文档中。

我已经制作了这个情节。它与图7中的7英寸x完全成比例。我一直试图按比例缩放到8厘米x 8厘米的图形,但收效甚微:命令“缩放”仅适用于轴字体标签(例如,不适用于刻度线长度),标准的“cex”在xyplot仅适用于符号大小。我想按比例缩放整个图(标签与轴的距离,刻度长度,图例等等)。

谢谢!

这是一个可能的代码:

# libraries
library(lattice)
library(grid)
library(RColorBrewer)

#creating dataset
x <- rnorm(100,10,3)
y <- rnorm(100,3,10)
z <- seq(1,100)

data <- data.frame(x,y)
data$z <- z
data$col <- heat.colors(100)

#making well scaled plot
pdf("plot.pdf")

my.legend <- packGrob(
    draw.colorkey(key=list(col = heat.colors,at = do.breaks(range(data$z,na.rm=T),100))),
    textGrob(expression(paste("z (no units)")), x = -.3, y = 0.5, just = c("left", "centre")), 
    height=unit(2, "lines"),side="top", dynamic=T)

xyplot(y~x, data, aspect="fill", type=c("p","g"), pch=21, col=grey(.2), fill=data$col, xlab=list(label=expression(paste("x axis label"[bla],", ",mu,"-"))),ylab=list(label=expression(paste("y axis label"[bla],", ",mu,"-"))),
       legend=list(right=list(fun=my.legend)),
       panel=function(x,y,...){
           panel.xyplot(x,y,...)
       }   
)
dev.off()

#trying to make a 8cm x 8cm plot
pdf("plot_small.pdf",width=8/2.54,height=8/2.54)

my.legend <- packGrob(
    draw.colorkey(key=list(col = heat.colors,at = do.breaks(range(data$z,na.rm=T),100))),
    textGrob(expression(paste("z (no units)")), x = -.3, y = 0.5, just = c("left", "centre")), 
    height=unit(2, "lines"),side="top", dynamic=T)

xyplot(y~x, data, aspect="fill", type=c("p","g"), pch=21, col=grey(.2), fill=data$col, cex=.5, xlab=list(label=expression(paste("x axis label"[bla],", ",mu,"-")),cex=.5),ylab=list(label=expression(paste("y axis label"[bla],", ",mu,"-")),cex=.5),
       legend=list(right=list(fun=my.legend)),
       panel=function(x,y,...){
           panel.xyplot(x,y,...)
       },
       scales=list(cex=.5)
)
dev.off()

0 个答案:

没有答案