Adding an arrow to indicate a scale value in R

I wonder how to add an arrow to point directly to a specific value in the scale next to the graph.

Let's say that I have different values ​​in different years. I want to know what value is in a particular year by pointing it directly to the scale. For example, I want to know what the meaning in 2010 is. Then the scale will indicate, as in the image below:

An arrow has been added to this image. enter image description here

What would I really appreciate (and I don’t know how to do this), it prints only a scale with an arrow without a graph, so that I can put the scale on which I want on another graph. A bit like this: enter image description here

Here is the code for reproducing the image without an arrow ( this code greatly influenced the creation of scale ).

effort = structure(c(-1.2696471203597, 0.176082447349155, 1.17697214807067, 
                          -0.101942469517932, -1.04722718686603, -0.99162220349261, 0.0648724806023204, 
                          2.40028178228585, 0.00926749722890297, -0.101942469517932, 0.00926749722890297, 
                          -0.324362403011601), .Dim = c(12L, 1L), "`scaled:center`" = 127.333333333333, "`scaled:scale`" = 71.9359984902405, decostand = "standardize", .Dimnames = list(
                            c("2003", "2004", "2005", "2006", "2007", "2008", "2009", 
                              "2010", "2011", "2012", "2013", "2014"), NULL))
plot(effort, type = "n")

image.scale <- function(z, zlim, col = heat.colors(12),
                        breaks, horiz=TRUE, ylim=NULL, xlim=NULL, ...){
  if(!missing(breaks)){
    if(length(breaks) != (length(col)+1)){stop("must have one more break than colour")}
  }
  if(missing(breaks) & !missing(zlim)){
    breaks <- seq(zlim[1], zlim[2], length.out=(length(col)+1)) 
  }
  if(missing(breaks) & missing(zlim)){
    zlim <- range(z, na.rm=TRUE)
    zlim[2] <- zlim[2]+c(zlim[2]-zlim[1])*(1E-3)#adds a bit to the range in both directions
    zlim[1] <- zlim[1]-c(zlim[2]-zlim[1])*(1E-3)
    breaks <- seq(zlim[1], zlim[2], length.out=(length(col)+1))
  }
  poly <- vector(mode="list", length(col))
  for(i in seq(poly)){
    poly[[i]] <- c(breaks[i], breaks[i+1], breaks[i+1], breaks[i])
  }
  xaxt <- ifelse(horiz, "s", "n")
  yaxt <- ifelse(horiz, "n", "s")
  if(horiz){YLIM<-c(0,1); XLIM<-range(breaks)}
  if(!horiz){YLIM<-range(breaks); XLIM<-c(0,1)}
  if(missing(xlim)) xlim=XLIM
  if(missing(ylim)) ylim=YLIM
  plot(1,1,t="n",ylim=ylim, xlim=xlim, xaxt=xaxt, yaxt=yaxt, xaxs="i", yaxs="i", ...)  
  for(i in seq(poly)){
    if(horiz){
      polygon(poly[[i]], c(0,0,1,1), col=col[i], border=NA)
    }
    if(!horiz){
      polygon(c(0,0,1,1), poly[[i]], col=col[i], border=NA)
    }
  }
}

# source("image.scale.R")

layout(matrix(c(1,2,3,0,4,0), nrow=1, ncol=2), widths=c(4,4,1), heights=c(4,1))
layout.show(4)

pal.1=colorRampPalette(c("red", "orange", "yellow"), space="rgb")
breaks <- seq(min(effort),max(effort),length.out = 10)
par(mar=c(1,1,1,8))
image(effort,col=pal.1(length(breaks)-1), breaks=breaks, xaxt="n", ylab="", xlab="")
#Add additional graphics
points(x = 1:12, y = effort , 
       pch=1, lwd=2, cex=1,col="black")

#Add scale
par(mar=c(1,1,1,3))
image.scale(effort, col=pal.1(length(breaks)-1), breaks=breaks, horiz=FALSE, yaxt="n")
axis(4,at=breaks, las=2)
+4
1

, text , arrows. effort y . 1 xpd=TRUE, / . , , .

par(mar=c(1,4,1,4))
image.scale(effort, col=pal.1(length(breaks)-1), breaks=breaks, horiz=FALSE, 
            yaxt="n", ylab="")
axis(4,at=breaks, las=2)
text(-0.11, effort, rownames(effort), cex=0.8, col="red", xpd=TRUE)
arrows(-0.07, effort, x1=-0.01, length=0.1, col="red", xpd=TRUE)

, , .

enter image description here


1 ( x, y) ? , , .

+1

All Articles