0

I'd like to create plot global temperature anomalies (recorded and projected) from 1950-2114 on a log-10 timescale as colors on a yellow-red color gradient.

Based on answers to this question, I've been able to create a color bar that is more or less what I'm aiming for, except that the time-scale is linear, not logarithmic.

This is the code I used, with a dummy vector dataset.

temps<-rnorm(165)

scaled_temps <- (temps - min(temps)) / diff(range(temps))

FUN <- colorRamp(c("yellow","red"))

cols <- FUN(scaled_temps)

rgb(cols, maxColorValue=256)

my.colors = colorRampPalette(c(rgb(cols, maxColorValue=256)))

z=matrix(1:165,nrow=165)
y=1
x=seq(1950, 2114,len=165)
image(x,y,z,col=my.colors(165),axes=FALSE,xlab="",ylab="")
axis(1)

Any thoughts on how to plot this on a log-scale? Using a matrix and image may not be the way to go, given that the color for each year won't have a fixed width.

Any input would be appreciated.

Community
  • 1
  • 1

1 Answers1

0

I should have read the help file for image more carefully. I replaced x=seq(1950, 2114,len=165) with a vector of log10 transformed year values calculated (in a csv, previously) as:

-LOG10(YBP) for years before 2014,

and

Log10(YBP) for years after 2014

where YBP = 2014-[year]

Because the log-transformed values for years 2014 and 2015 needed to be fudged slightly (to prevent an undefined value for the present year and to maintain an ascending order of grid lines for the x argument). (Not desirable, but acceptable for my purposes.) Without this fudging, the sequence of log-transformed years for 2013, 2014, and 2015 would be

0, undefined, 0

From the imagehelp file:

x argument- locations of grid lines at which the values in z are measured. These must be finite, non-missing and in (strictly) ascending order. By default, equally spaced values from 0 to 1 are used.