简体   繁体   English

将刻度颜色更改为 R 中的特定数字

[英]Changing scale colour to specific number in R

I've uploaded my data onto github here: https://github.com/dschmidt42/Benguela_Chla_Danielle_Schmidt .我已将我的数据上传到 github: https://github.com/dschmidt42/Benguela_Chla_Danielle_Schmidt

To set up my data:设置我的数据:

chl_data <- "cmems_mod_glo_bgc_my_0.25_P1M-m_1673881119174.nc"
r <- rast(chl_data)
i <- seq(1, nlyr(r), 3) 
r1 <- r[[i]]
vm <- tapp(r1, "months", var)

Here are the resulting plots:以下是结果图:

titles <- c("January", "February", 
            "March", "April", 
            "May", "June", 
            "July", "August", 
            "September", "October",
            "November", "December")
plot(vm, main = titles)

在此处输入图像描述

As you can see, the scales are all the same though they have different values.正如您所看到的,尽管它们具有不同的值,但比例都是相同的。 How can I change it so that 4.0 on one graph is not the same as 1.5 on another?我怎样才能改变它,使一张图表上的 4.0 与另一张图表上的 1.5 不同?

You can try setting the breaks manually and the type of the rasters as continuous.您可以尝试手动设置中断并将栅格类型设置为连续。

library(terra)
plot(vm, 
     main = titles,
     type = "continuous",
     breaks = seq(0,4,0.5))

There really ought to be a simple way to specify that you want that, but for now, a quick solution is确实应该有一种简单的方法来指定您想要的,但是现在,一个快速的解决方案是

rr <- range(minmax(vm))
plot(vm, range=rr, main=month.name)

A more elaborate solution is一个更复杂的解决方案是

m <- cbind(matrix(1:12, ncol=4, byrow=TRUE), 13)
layout(m, c(1,1,1,1,.3))
for (i in 1:12) {
    plot(vm[[i]], legend=i==8, range=rr, mar=c(1,1,1,1), plg=list(cex=1.2))
    text(20,-17,month.abb[i])
}

And more:和更多:

m <- cbind(matrix(1:12, ncol=4, byrow=TRUE), 13)
layout(m, c(1, 1, 1, 1, .5))
par(mgp = c(2, .25, 0))
for (i in 1:12) {
    plot(vm[[i]], legend=i==8, range=rr, mar=c(1.2,1.2,.2,0), plg=list(cex=1.2), axes=FALSE)
    if (i %in% c(1,5,9)) axis(2, las=1, cex.axis=0.7)
    if (i > 8) axis(1, cex.axis=0.7)
    box()
    text(19,-17,month.abb[i])
}

在此处输入图像描述

Removing whitespace (while keeping outside axes), and using the log to get more contrast删除空格(同时保留外轴),并使用日志获得更多对比度

lvm <- log(vm)
lrr <- range(minmax(lvm))
m <- matrix(1:12, ncol=4, byrow=TRUE)
m <- rbind(m, 14)
m <- cbind(14, m, 13)

layout(m, c(0.2, 1, 1, 1, 1, .5), c(1,1,1,0.1))
par(mgp = c(2, .25, 0))
for (i in 1:12) {
    plot(lvm[[i]], legend=i==8, range=lrr, mar=c(0,0,0,0), plg=list(cex=1.2), axes=FALSE)
    if (i %in% c(1,5,9)) axis(2, las=1, cex.axis=0.7)
    if (i > 8) axis(1, cex.axis=0.7)
    box()
    text(19,-17,month.abb[i])
}

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM