【问题标题】:Produce single plot and conditioning plot in trellis graphics在格子图形中生成单个图和条件图
【发布时间】:2015-03-25 16:27:04
【问题描述】:

您好:我正在为我正在教授的一门课程使用“提示”数据集。我想生成一个 .png 文件,该文件在绘图设备的顶行(理想情况下在窗口的中心顶部)具有小费作为大小的函数,底行是条件图提示作为大小的函数,由从数据集中包含的 total_bill 变量重新编码的分类变量分组。我对 ggplot2 环境更加熟悉,尽管我也不太清楚如何在那里执行此操作。 谢谢!

library(reshape2)
library(grid)
library(lattice)
data(tips)
tips$bill2<-cut(tips$total_bill, breaks=3, labels=c('low', 'medium', 'high'))
#Create one plot window with this plot on the top row, ideally in the center
xyplot(tip~size, data=tips,type=c('r', 'p'))
#With this plot in the second row
xyplot(tip~size|bill2, data=tips, type=c('r', 'p'))

【问题讨论】:

    标签: r plot lattice


    【解决方案1】:

    您可以将split 参数用于print

    p1 <- xyplot(tip~size, data=tips,type=c('r', 'p'))
    p2 <- xyplot(tip~size|bill2, data=tips, type=c('r', 'p'))
    
    print(p1,split=c(1,1,1,2),more=TRUE)
    print(p2,split=c(1,2,1,2),more=FALSE)
    

    ?print.trellis

    更新:调整大小

    那也是?print.trellis

    print(p1,split=c(1,1,1,2),more=TRUE,position=c(.3,0,.7,1))
    print(p2,split=c(1,2,1,2),more=FALSE)
    

    如果您愿意,请调整 position

    顺便说一句,lattice 可能并不总是将您的第二个绘图排列为一行中的 3 个面板,具体取决于图形窗口的形状。您可以通过

    强制执行此操作
    p2 <- xyplot(tip~size|bill2, data=tips, type=c('r', 'p'),layout=c(3,1))
    

    【讨论】:

    • 嗨,这样可以,但顶部的情节延伸到第二行的所有三个情节。有没有办法限制它只填充中心列(情节?)
    猜你喜欢
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 2015-05-31
    • 1970-01-01
    • 1970-01-01
    • 2022-10-15
    • 1970-01-01
    相关资源
    最近更新 更多