[R] Control color palette and legend in filled.contour
Thiago V. dos Santos
thi_veloso at yahoo.com.br
Wed Sep 17 10:53:05 CEST 2014
Dear all,
I am having some difficulties trying to control color palette and legend of a filled.countour plot.
Basically, I am plotting volumetric soil moisture which ranges from 0 to 1 (although the data excerpt I'm providing here ranges from 0 to 0.4, my complete dataset ranges from 0 to 1). Low values mean dry soil and higher values denote wet soil.
Instead of the default color palette, I would like to set a 'red to blue' palette with legend ranging from 0 (red) to 1 (blue). My final goal is to achive a color palette and legend similar to this figure: https://imageshack.com/i/exmVz5QSp.
A sample of my data (as well as an attemptive plot) can be reproduced with this code:
-------------------------------------------------------------------------------------------------
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)
head(data)
# define vector with depth of soil layers
depths <- c(0.05,0.10,0.20,0.30,
0.40,0.60,0.80,1.00,
1.50,2.00,2.50)
# Plot soil moisture profile
cols <- ncol(data):4
x11(width=15, height=6, pointsize=12)
op <- par(mar = c(3,5,12,3))
plot <- filled.contour(x= date,
y= sort(-depths),
z= as.matrix(data[, cols]),
ylab= expression(theta(m^3~~m^-3)))
# also plot rainfall
par(new=T,mar=c(19,5,1,9))
with(data,
plot(date, precip, type = "h", xaxt = "n", xpd = T, xaxs="i", ylab = "Precip (mm)", xlab = ""))
par(op)
-------------------------------------------------------------------------------------------------
I have some experience with R but I used to work with ggplot2, and therefore I am not very familiar with fine-tuning plots created with the base graphical package.
I thank in advance for any suggestion or advice.
Greetings,
--
Thiago V. dos Santos
PhD student
Land and Atmospheric Science
University of Minnesota
http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
Phone: (612) 323 9898
[[alternative HTML version deleted]]
More information about the R-help
mailing list