字幕与图像分离

时间:2016-11-02 16:50:03

标签: r image graphics title subtitle

我有以下代码构建混淆矩阵图像:

truth <- c(0,1,0,0,0,1,0,1,0,1)
pred  <- c(0,0,0,0,0,1,0,1,0,0)
FWConf <- mlearning::confusion(factor(pred,labels=c("Loyal","Churn")), factor(truth,labels=c("Loyal","Churn")),vars=c("a","b"), labels = c("Actual","Predicted"))
opar <- par(mar=c(14, 4, 7, 2))
x <- x.orig <- unclass(FWConf)
x <- log(x + 0.5) * 2.33
x[x < 0] <- NA
x[x > 10] <- 10
diag(x) <- -diag(x)

graphics::image(1:ncol(x), 1:ncol(x), -(x[, nrow(x):1]), xlab='', ylab='',col=colorRampPalette(c("red","yellow","green"))(41), xaxt='n', yaxt='n', zlim=c(-10, 10))

axis(1, at=1:ncol(x), labels=colnames(x), cex.axis=0.8)
axis(2, at=ncol(x):1, labels=colnames(x), las=1, cex.axis=0.8)
title(ylab='Predicted', line=0.5, xlab = 'Actual') 
abline(h = 0:ncol(x) + 0.5, col = 'gray')
abline(v = 0:ncol(x) + 0.5, col = 'gray')
text(1:6, rep(6:1, each=6), 
     labels = sub('^0$', '', round(c(x.orig), 0)))
box(lwd=2)
title(sub = paste("\n\n\n +-------------------------------------------------------+",
                  "\n\t[\tCosto Mancato Allarme:\t", 90      ,"\t euro\t]", 
                  "\n\t[\tCosto Falso Allarme  :\t", 10      ,"\t euro\t]", 
                  "\n\t[\tIndice di Salvataggio:\t", 0.4*100 ,"\t  %  \t]",
                  "\n+-------------------------------------------------------+"), 
      main = paste(" +-------------------------+","\n | Costo  = " ,10, " euro |", "\n+-------------------------+"))
par(opar)

生成的图像是: enter image description here

为了将字幕与图像分开,我按以下方式更改了标题部分。

title(main = paste(" +-------------------------+","\n | Costo  = " ,costo, " euro |", "\n+-------------------------+"))
title(sub = paste("\n\n\n +-------------------------------------------------------+",
                      "\n[\tCosto Mancato Allarme:\t", z2            ,"\t euro\t]", 
                      "\n[\tCosto Falso Allarme  :\t", z1            ,"\t euro\t]", 
                      "\n[\tIndice di Salvataggio:\t", savingRate*100,"\t  %  \t]",
                      "\n+-------------------------------------------------------+"), 
        line = 7
)

enter image description here

有没有更好的方法来显示标题,副标题和图片中包含的信息?像盒子,矩形等东西?

0 个答案:

没有答案
相关问题