精细调整R格子包中的点图

use*_*195 4 r lattice

我试图为不同的数据集和不同的算法绘制一堆ROC区域.我有三个变量:"Scheme",它指定使用的算法,"Dataset"是正在测试算法的数据集,以及"Area_under_ROC".

我使用R中的晶格库,使用以下命令:

dotplot(Scheme~Fare_under_ROC | Dataset,data = simulationSummary,layout = c(4,6))

这就是我得到的:

Scheme与Area_under_ROC的dotplot以Dataset为条件

我想知道的是

  • 如何使y轴上的标签可读?现在,他们都挤在了一起.
  • 如何以这样的方式重新排列面板:标记为"100"的数据集构成最后一列,但其他列保持不变?

我非常感谢任何评论或指示.非常感谢!

chl*_*chl 9

一些想法:

  1. 对y轴标签使用较小的字体大小,例如scale=list(y=list(cex=.6)).另一种方法是保留统一的字体大小,但将输出分隔在几个页面上(可以用它控制layout=),或者更好的是,显示来自同一数据集的所有数据(A到F,因此每个算法有4个点)或者通过样本大小(10到100,因此每个算法6个点)和一个group=选项.我会亲自创建两个因素,sample.sizedataset.type对于这一点.
  2. 重新调整您的因子Dataset,以便您感兴趣的数据集出现在layout放置它们的位置,或者(更好!)用于index.cond指定24个面板的特定排列.例如,

    dfrm <- data.frame(algo=gl(11, 1, 11*24, labels=paste("algo", 1:11, sep="")), 
                       type=gl(24, 11, 11*24, labels=paste("type", 1:24, sep="")),
                       roc=runif(11*24))
    p <- dotplot(algo ~ roc | type, dfrm, layout=c(4,6), scale=list(y=list(cex=.4)))
    
    Run Code Online (Sandbox Code Playgroud)

    将按顺序排列面板,从左下角到右上角(type1左下方面板,type24右上角),同时

    update(p, index.cond=list(24:1))
    
    Run Code Online (Sandbox Code Playgroud)

    将按相反的顺序安排面板.只需指定list具有预期面板位置的a.


以下是我对第1点的想法和使用两个因素而不是一个因素的例子.让我们生成另一个人工数据集:

dfrm <- data.frame(algo=gl(11, 1, 11*24, labels=paste("algo", 1:11, sep="")),
                   dataset=gl(6, 11, 11*24, labels=LETTERS[1:6]),
                   ssize=gl(4, 11*6, 11*24, labels=c(10,25,50,100)), 
                   roc=runif(11*24))
xtabs(~ dataset + ssize, dfrm)  # to check allocation of factor levels 
dotplot(algo ~ roc | dataset, data=dfrm, group=ssize, type="l", 
        auto.key=list(space="top", column=4, cex=.8, title="Sample size", 
                      cex.title=1, lines=TRUE, points=FALSE))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Mar*_*rek 5

除了 将类型拆分为Type和Size 之后的chl回答,Dataset您可以使用useOuterStrips来自latticeExtra包的函数.

为了获得更多标签空间,您可以"转置"绘图.

# prepare data:
simulationSummary$Dataset_type <- substr(simulationSummary$Dataset, 1, 5)
simulationSummary$Dataset_size <- substr(simulationSummary$Dataset, 6, 10)

# to gets proper order force factor levels:
simulationSummary$Dataset_size <- factor(simulationSummary$Dataset_size,
    levels = c("10", "25", "50", "100"))

library(latticeExtra)
useOuterStrips(dotplot(
     Scheme ~ Area_under_ROC | Dataset_type*Dataset_size,
     data = simulationSummary,
     layout = c(4,6)
))
Run Code Online (Sandbox Code Playgroud)

散点图

或者使用垂直dotplot:

useOuterStrips(dotplot(
     Area_under_ROC ~ Scheme | Dataset_size*Dataset_type,
     data = simulationSummary, horizontal=FALSE,
     layout = c(4,6), scales=list(x=list(rot=90))
))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述