I would like to make a map plot using image.plot. I have done this oftentimes before and it always worked well, but now with this new data set I am facing a problem. I am aware that there are quite a few posts about this error message here already. I checked them but none of them seemed to be applicable to my case. The data contains surface temperature values for the Po Valley region and is supposed to be plotted now. The temperature values are contained in a 2D matrix, vectors provide the longitude and latitude values. The dimensions are matching.
Here is some code for an reproducible example:
# here are the lon and lat values
lon <- c(7.018677, 7.018707, 7.018708, 7.018709, 7.018736, 7.018737, 7.018738, 7.018739, 7.018767, 7.018768, 7.018769,
7.018797, 7.018798, 7.018799, 7.018827, 7.018828, 7.018829, 7.018859, 7.018860, 7.018861, 7.018862, 7.018889,
7.018890, 7.018891, 7.018920, 7.018921, 7.018922, 7.018950, 7.018951, 7.018952, 7.018980, 7.018981, 7.018982,
7.018983, 7.019011, 7.019012, 7.019013, 7.019042, 7.019043, 7.019044, 7.019072, 7.019073, 7.019074, 7.019103,
7.019104, 7.019105, 7.019134, 7.019135, 7.019136, 7.019164, 7.019165, 7.019166, 7.019194, 7.019195, 7.019196,
7.019197, 7.019225, 7.019226, 7.019227, 7.019256, 7.019257, 7.019258, 7.019286, 7.019287, 7.019288, 7.019317,
7.019318, 7.019319, 7.019347, 7.019348, 7.019349, 7.019378, 7.019379, 7.019380, 7.019408, 7.019409, 7.019410,
7.019439, 7.019440, 7.019441)
lat <- c(44.01695, 44.01693, 44.01691, 44.01687, 44.01682, 44.01675, 44.01667, 44.01658, 44.01647, 44.01635, 44.01622,
44.01607, 44.01591, 44.01573, 44.01555, 44.01535, 44.01514, 44.01492, 44.01467, 44.01442, 44.01415, 44.01387,
44.01358, 44.01327, 44.01296, 44.01262, 44.01228, 44.01192, 44.01154, 44.01115, 44.01075, 44.01035, 44.00991,
44.00947, 44.00902, 44.00856, 44.00807, 44.00758, 44.00708, 44.00656, 44.00602, 44.00549, 44.00492, 44.00435,
44.00377, 44.00316, 44.00255, 44.00193, 44.00129, 44.00064, 43.99997, 43.99929, 43.99860, 43.99789, 43.99717,
43.99644, 43.99569, 43.99494, 43.99417, 43.99338, 43.99257, 43.99177, 43.99094, 43.99010, 43.98925, 43.98839,
43.98751, 43.98662, 43.98571, 43.98479, 43.98386, 43.98292, 43.98196, 43.98099, 43.98000, 43.97900, 43.97799,
43.97696, 43.97593, 43.97488, 43.97381, 43.97274, 43.97165, 43.97054, 43.96942, 43.96829, 43.96714, 43.96598,
43.96482, 43.96363, 43.96244, 43.96123, 43.96000, 43.95877, 43.95752, 43.95625, 43.95497, 43.95369, 43.95238,
43.95106, 43.94973, 43.94839, 43.94703, 43.94566, 43.94427, 43.94288, 43.94147, 43.94005, 43.93861, 43.93717,
43.93570, 43.93423, 43.93274, 43.93123, 43.92972, 43.92819, 43.92664, 43.92509, 43.92352, 43.92194, 43.92035,
43.91874, 43.91711, 43.91548, 43.91383, 43.91217, 43.91050, 43.90881, 43.90710, 43.90539, 43.90367, 43.90192,
43.90016, 43.89840, 43.89662, 43.89483, 43.89302, 43.89120, 43.88937, 43.88752, 43.88566, 43.88379, 43.88190,
43.88000, 43.87809, 43.87616, 43.87422, 43.87227, 43.87030, 43.86833, 43.86634, 43.86433, 43.86231, 43.86029,
43.85824, 43.85618, 43.85411, 43.85202, 43.84992, 43.84781)
You can verify by diff(lon)==0 and diff(lat)==0 that there are always differences between the single values, they follow an order.
Here is a matrix of values that represents the 2D temperature field:
T.vec <-runif(n= 160*60, min= -2, max= 30)
T.matrix <- matrix(T.vec, nrow= 160, ncol= 80)
Now this matrix should be plotted on a map:
col <- c("seashell", "seashell2", "seashell3", "yellow2", "orange", "orange3", "tomato3", "red3", "red4") # set the color palette
image.plot(lat, rev(lat), T.matrix,
main = "Monthly Mean Surface Temperature",
cex.main= 2.4,
col = col,
cex.axis= 2.2,
xlab = "",
ylab = "",
legend.line = 2.5,
breaks= seq(-5, 35, 5),
axis.args = list(seq(-5, 35, 5), cex.axis= 2.08))
But the error message Error in image.default(..., breaks = breaks, add = add, col = col) : increasing 'x' and 'y' values expected appears, even though the lat and lon values are increasing.
Anybody with a hint?