【问题标题】:image plots with color key legends in layout布局中带有颜色键图例的图像绘图
【发布时间】:2021-07-23 05:39:10
【问题描述】:

我想制作这样排列的情节,但带有色键图例。

layout(matrix(c(1,1,2,3,2,3),2,3))
y <- matrix(1:200,10,20)
par(mai=c(0.9,0.9,0.1,0.1))
plot(1,1)
par(mai=c(0.6,0.6,0.1,0.8))
image(y)
image(y)

此代码的问题是图像图没有颜色键图例。 image.plot 可以制作图例,但image.plot 不适用于layout。有人问过这个问题here,但没有得到回答。

layout(matrix(c(1,1,2,3,2,3),2,3))
y <- matrix(1:200,10,20)
par(mai=c(0.9,0.9,0.1,0.1))
plot(1,1)
par(mai=c(0.6,0.6,0.1,0.8))
library(fields)    
image.plot(y)
image.plot(y)

我试图用addLegend创造一个传奇,

layout(matrix(c(1,1,2,3,2,3),2,3))
y <- matrix(1:200,10,20)
par(mai=c(0.9,0.9,0.1,0.1))
plot(1,1)
par(mai=c(0.6,0.6,0.1,0.8))
library(fields)
image(y,col=hcl.colors(12, "RdYlBu", rev = TRUE))
addLegend(setupLegend(), col=hcl.colors(12, "RdYlBu", rev = TRUE), zlim = c(0,200))
image(y,col=hcl.colors(12, "RdYlBu", rev = TRUE))
addLegend(setupLegend(), col=hcl.colors(12, "RdYlBu", rev = TRUE), zlim = c(0,200))

但还是有问题。我喜欢在不使用 ggplot 的情况下制作绘图。

【问题讨论】:

    标签: r plot layout


    【解决方案1】:

    color.legend 工作正常。

    layout(matrix(c(1,1,2,3,2,3),2,3))
    y <- matrix(1:200,10,20)
    par(mai=c(0.9,0.9,0.1,0.1))
    plot(1,1)
    par(mai=c(0.6,0.6,0.1,0.6))
    library(fields)
    library(plotrix)
    
    image(y,col=hcl.colors(12, "RdYlBu", rev = TRUE))
    color.legend(1.1,0,1.15,1,c(1,100,200),hcl.colors(12, "RdYlBu", rev = TRUE),gradient="y",align="rb")
    image(y,col=hcl.colors(12, "RdYlBu", rev = TRUE))
    color.legend(1.1,0,1.15,1,c(1,100,200),hcl.colors(12, "RdYlBu", rev = TRUE),gradient="y",align="rb")
    

    【讨论】:

      猜你喜欢
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-12
      • 2018-09-24
      • 1970-01-01
      • 2022-06-22
      • 1970-01-01
      相关资源
      最近更新 更多