r语言 - 将不同类型的图形与"lattice"和"latticeExtra"组合/叠加



我正在尝试组合,或者是说用xyplot(带回归线)的barchart用两个变量叠加,其值大不相同。

这是我的数据:https://www.dropbox.com/s/aacbkmo5777777777777uagjs/example.csv

有两个数字变量" rb"one_answers" rae",以及几个因子变量(sample.size,size,feltim.size,size,分配。设计,true.dose),根据下面的代码在面板中显示。变量" rae"应显示在巴尔查特(理想情况下是背景中的微弱颜色),而变量" rb"将显示在带有回归线的xyplot中。有两个主要问题:

(1)如何将两种类型的图形组合在一起?(2)如何自定义轴标签(y尺度的不同尺度)

对于(1),我知道如何将不同类型的图与ggplot2结合在一起,但是晶格也应该可以使用,对吗?我尝试了"双刻度",这似乎不起作用。

对于(2),我只完成了"关系='free'"的" scales" - 选项中的y量表(请参阅代码)。这很好,因为重点是值的重要范围。但是,如果另外在左侧和右侧绘制轴标签,则将更合适(分别为" Rae"one_answers" RB")。

这是到目前为止的代码(由Dieter Menne修改为独立的)

library(lattice)
library(latticeExtra)
df.dose <- read.table("example.csv", header=TRUE, sep=",")
df.dose <- transform(df.dose, 
                    sample.size=as.factor(sample.size),
                    true.dose = as.factor(true.dose))
rae.plot <- xyplot(
  rae ~ sample.size | allocation.design*true.dose,                
  df.dose, as.table=TRUE, 
  groups = type, 
  lty = 1, jitter.x=TRUE, 
  main="RAE", 
  scales=list(y=list(draw=F, relation="free", tck=.5)), 
  panel = function(x,y) { 
    panel.xyplot(x,y,jitter.x=TRUE)
    panel.lmline(x,y, col="darkgrey", lwd=1.5) 
  })
useOuterStrips(rae.plot)
rb.plot <- barchart(
  rb ~ sample.size | allocation.design*as.factor(true.dose), 
  df.dose, as.table=TRUE, 
  groups = type, 
  key=list(
    text=list(levels(as.factor(df.dose$type))), 
    scales=list(y=list(draw=F, relation="free", tck=.5)), 
    main="RB"))
useOuterStrips(rb.plot)
print(useOuterStrips(rae.plot), split=c(1,1,1,2),more=TRUE)
print(useOuterStrips(rb.plot), split=c(1,2,1,2), more=FALSE)

将在一个页面上打印两个;它比ggplot2更容易。

scales=list(
  y=list(alternating=1,tck=c(1,0)),
  x=list(alternating=1,tck=c(1,0)))
xyplot (... scales=scales)

最新更新