gpt4 book ai didi

r - 水平图颜色键 - 范围和极值

转载 作者:行者123 更新时间:2023-12-04 23:14:10 24 4
gpt4 key购买 nike

是否可以在 R 中创建如下所示的颜色键? (这个来自软件Grid Analysis and Display System - Grads)。

enter image description here

我无法在 R 中重现两个功能:

  • 该序列是非线性的,但显示为
  • 大于 200 的值是灰色/小于 0 的值是白色

  • 我正在使用来自 rastervis 的 levelplot,它使用点阵 levelplot 绘制栅格:
    require(raster)
    require(rasterVis)

    set.seed(200)

    X = seq(-40,0,by=1)
    Y = seq(-60,-40,by=1)
    grid = expand.grid(list(X=X,Y=Y))
    Z = rnorm(nrow(grid),mean=10,sd=100)

    data = data.frame(grid,Z)
    r = rasterFromXYZ(data)
    mapTheme <- rasterTheme(region=c('#EEF7FA','#D6F8F7',"#BEDAFF",'#5DA4FF',"#0000FF","#D4F9E2","#00FF7F","#008000","#FFFF00","#FFD27F", "#FFB732" ,"#EE7600",
    "#D53E4F","#FF6A6A"))
    my.at = c(0,1,5,10,15,20,25,30,40,50,75,100,150,200)
    myColorkey <- list(at=my.at,
    space="bottom",
    labels=list(at=my.at))
    p=levelplot(r, par.settings=mapTheme,at = my.at, colorkey=myColorkey,margin=F)
    print(p)

    结果:

    enter image description here

    如您所见,小于 0 和大于 200 的值都是白色的,我不知道如何设置大于或小于某个值的值以显示为特定颜色。 Morover,如何使颜色键中连续粗标记之间的空间具有相同的大小,尽管间隔不相同?

    最佳答案

    这是用于非线性序列的相同大小间隔的解决方法:

    library(raster)
    library(rasterVis)

    set.seed(200)
    X = seq(-40,0,by=1)
    Y = seq(-60,-40,by=1)
    grid = expand.grid(list(X=X,Y=Y))
    Z = rnorm(nrow(grid),mean=10,sd=100)

    data = data.frame(grid,Z)
    r = rasterFromXYZ(data)
    mapTheme <- rasterTheme(region=c('#EEF7FA','#D6F8F7',"#BEDAFF",'#5DA4FF',"#0000FF","#D4F9E2","#00FF7F",
    "#008000","#FFFF00","#FFD27F", "#FFB732" ,"#EE7600", "#D53E4F","#FF6A6A"))

    my.at=c(0,1,5,10,15,20,25,30,40,50,75,100,150,200)
    my.brks=seq(0, 200, by=15)

    myColorkey <- list(at=my.brks, labels=list(at=my.brks, labels=my.at), space="bottom")
    p=levelplot(r, par.settings=mapTheme, at=my.at, colorkey=myColorkey, margin=F)
    print(p)

    enter image description here

    对于小于 0 且大于 200 的值,这可能是一个解决方案:
    library(raster)
    library(rasterVis)

    set.seed(200)
    X = seq(-40,0,by=1)
    Y = seq(-60,-40,by=1)
    grid = expand.grid(list(X=X,Y=Y))
    Z = rnorm(nrow(grid),mean=10,sd=100)

    data = data.frame(grid,Z)
    r = rasterFromXYZ(data)
    mapTheme <- rasterTheme(region=c('white','#EEF7FA','#D6F8F7',"#BEDAFF",'#5DA4FF',"#0000FF","#D4F9E2","#00FF7F",
    "#008000","#FFFF00","#FFD27F", "#FFB732" ,"#EE7600", "#D53E4F","#FF6A6A", "gray"))
    max(values(r))
    min(values(r))

    my.at=c(min(values(r)), 0,1,5,10,15,20,25,30,40,50,75,100,150,200, max(values(r)))
    my.brks=seq(0, 200, by=13)

    myColorkey <- list(at=my.brks, labels=list(at=my.brks, labels=c(-276,0,1,5,10,15,20,25,30,40,50,75,100,150,200, 388)), space="bottom")
    p=levelplot(r, par.settings=mapTheme, at=my.at, colorkey=myColorkey, margin=F)
    print(p)

    enter image description here

    你的颜色没有从浅到深。您可以使用 RColorBrewer 包来解决这个问题。
    library(RColorBrewer)
    reds = brewer.pal(5, "YlOrRd")
    greens = brewer.pal(3, "Greens")
    blues = brewer.pal(5, "Blues")
    mapTheme <- rasterTheme(region=c('white', blues, greens, reds, "gray"))

    enter image description here

    关于r - 水平图颜色键 - 范围和极值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47459083/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com