首页 文章

热图像莱迪思的情节

提问于
浏览
2

我无法弄清楚格子 levelplot 是如何工作的 . 我现在玩了一段时间,但找不到合理的解决方案 .

样本数据:

Data <- data.frame(x=seq(0,20,1),y=runif(21,0,1))
Data.mat <- data.matrix(Data)

用levelplot绘图:

rgb.palette <- colorRampPalette(c("darkgreen","yellow", "red"), space = "rgb")

levelplot(Data.mat, main="", xlab="Time", ylab="", col.regions=rgb.palette(100),   
          cuts=100, at=seq(0,1,0.1), ylim=c(0,2), scales=list(y=list(at=NULL)))

这是结果:

enter image description here

因为,我不明白这个级别图是如何工作的,我无法使它工作 . 我想要的是用于填充相应 x (时间)的整个窗口的颜色条 .

其他方法的替代解决方案 .

基本上,我在这里尝试绘制随着时间推移而增加的风险,其中红色是最高的风险= 1.我想想象随着时间的推移可能增加或聚类风险的顺序 .

2 回答

  • 2

    ?levelplot 我们被告知如果第一个参数是矩阵然后"'x' provides the 'z' vector described above, while its rows and columns are interpreted as the 'x' and 'y' vectors respectively.",那么

    > m = Data.mat[, 2, drop=FALSE]
    > dim(m)
    [1] 21  1
    > levelplot(m)
    

    绘制具有21列和1行的水平图,其中水平由m中的值确定 . 公式界面可能看起来像

    > df <- data.frame(x=1, y=1:21, z=runif(21))
    > levelplot(z ~ y + x, df)
    

    (这些方法不会产生相同的图像) .

  • 2

    不幸的是我对 lattice 了解不多,但我注意到你的"Alternative solution with other method",所以我可以提出另一种可能性:

    library(plotrix)
    color2D.matplot(t(Data[ , 2]), show.legend = TRUE, extremes = c("yellow", "red"))
    

    要做的事情要做得更漂亮 . 还是一个开始 . 当然,考虑时间变量的中断非常重要 . 在这个非常简单的尝试中,隐式假设了常规间隔,在您的示例中恰好是这种情况 .

    Update 遵循 ?color2D.matplot 中'Details'部分的建议:"The user will have to adjust the plot device dimensions to get regular squares or hexagons, especially when the matrix is not square" . 嗯,嗯,非常难看的解决方案 .

    par(mar = c(5.1, 4.1, 0, 2.1))
    windows(width = 10, height = 2.5)
    color2D.matplot(t(Data[ , 2]),
                    show.legend = TRUE,
                    axes = TRUE,
                    xlab = "",
                    ylab = "",
                    extremes = c("yellow", "red"))
    

    enter image description here

相关问题