[R] How to plot soil moisture data as a contour plot

Thiago V. dos Santos thi_veloso at yahoo.com.br
Wed Sep 10 22:20:01 CEST 2014

Dear all,

This is my first message in this list, so please excuse any mistake.

I am trying to plot moisture data for 11 soil layers over the course of the year, but I am yet to find the correct function to do that. I am trying to reproduce the lower figure in this panel: https://imageshack.com/i/exmVz5QSp

Please read the comments while reproducing my data with the code below: 

library(repmis) # reads text data directly from dropbox - no need to download any file

# read data
url <- 'https://dl.dropboxusercontent.com/u/27700634/precip.txt'
tmp <- repmis::source_data(url, sep = '', header = TRUE)

# convert julian day to date
date <- as.Date(tmp$julian, origin='2011-12-31')
data <- cbind(date, tmp)

# now, convert soil layers to matrix and transpose it
mat <- t(as.matrix(data[, 4:14]))

# this is the very matrix I want to plot. Please notice that it is already organized as a "profile",
# with rows representing soil layers and columns representing day of year.

My first attempt was to use function filled.contour from "graphics" package. I define a vector with labels for soil layers and then I try to plot, but I receive an error saying the matrix has incorrect dimensions:


# define vector with depth of soil layers

depths <- c(0.05,0.10,0.20,0.30,

# Plot soil moisture profile
plot <- filled.contour(data$julian, depths, mat)

#Error in .filled.contour(x, y, z, levels, col) : dimension mismatch

I can obviously tranpose the matrix to force the plot, but the resulting figure is not what I need - the soil profile is shown upside down:

plot <- filled.contour(data$julian, depths, t(mat))


Because this functions requires axis labels to be ascendent, I am not able to reverse them in order to show the first layer at the top of the graphic.

I would really appreciate any feedback or directions on how to show my data as a contour plot as mentioned above. Thanks in advance! 

Thiago V. dos Santos
PhD student
Land and Atmospheric Science
University of Minnesota
Phone: (612) 323
	[[alternative HTML version deleted]]

More information about the R-help mailing list