一种方法是编写带有原始的绘图功能来实现自己的自定义颜色栏绘图功能rect(),polygon()以及text().例如:
arrowedColorBar <- function(ylow,yhigh,xcenter,xwidth,nums,...,cols=rainbow(length(nums)+2L)) {
x1 <- xcenter-xwidth/2;
x2 <- xcenter+xwidth/2;
ys <- seq(ylow,yhigh,len=length(nums)+2L);
y1 <- ys[1L];
y2 <- ys[2L];
polygon(c(x1,xcenter,x2),c(y2,y1,y2),col=cols[1L]);
for (i in seq_along(nums)) {
y1 <- ys[i+1L];
y2 <- ys[i+2L];
if (i<length(nums)) rect(x1,y1,x2,y2,col=cols[i+1L]);
text(x2,y1,nums[i],pos=4L,...);
}; ## end for
y1 <- ys[length(ys)-1L];
y2 <- ys[length(ys)];
polygon(c(x1,xcenter,x2),c(y1,y2,y1),col=cols[length(cols)]);
invisible();
}; ## end arrowedColorBar()
plot(c(-80,-40),c(-60,20),pch=NA,xlab='x',ylab='y');
arrowedColorBar(-60,10,-45,1.3,c(1,2,3,4,5,7,10,13,15),font=2L);
Run Code Online (Sandbox Code Playgroud)