[英]Adjust color scale of image plot in R
這是一個稍微復雜的解決方案,它可以允許對刻度軸進行額外的控制:
library(sinkr) # https://github.com/marchtaylor/sinkr
x <- 1:10
y <- 1:15
z <- outer(x, y, "+")
ncolors <- 64
colors <- jetPal(ncolors)
zlim <- c(0,20)
breaks <- c(seq(zlim[1], zlim[2], length.out = ncolors), 1e6)
op <- par(no.readonly = TRUE)
layout(matrix(1:2,1,2), widths = c(4,1), heights = 4)
par(mar = c(4,4,1,1), cex = 1)
image(x, y, z, col = colors, breaks = breaks, zlim = zlim)
par(mar = c(4,0,1,4))
imageScale(z = z, ylim = zlim, zlim = zlim, col = colors, breaks = breaks,
axis.pos = 4)
par(op)
在這里,我展示了如何指定刻度軸標簽(例如添加 a >
):
# additional control
op <- par(no.readonly = TRUE)
layout(matrix(1:2,1,2), widths = c(4,1), heights = 4)
par(mar = c(4,4,1,1), cex = 1)
image(x, y, z, col = colors, breaks = breaks, zlim = zlim)
par(mar = c(4,0,1,4))
imageScale(z = z, ylim = zlim, zlim = zlim, col = colors, breaks = breaks,
axis.pos = 4, add.axis = FALSE)
axis(side = 4, at = seq(0,20,5),
labels = paste0(c(rep("", 4), ">"), seq(0,20,5)), las = 2)
mtext(text = "z", side = 4, line = 3)
par(op)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.