Skip to main content
1 de 3

Add contour lines to filled.contour plot

I am trying to create a contour plot with filled.contour but I would like to add contour lines to remark the significant values (I am plotting correlation values)

Here is the input file called ts_months_max

This is the code I am using:

# This function is from: https://warwick.ac.uk/fac/sci/moac/people/students/peter_cock/r/matrix_contour/
matrix.axes <- function(data) {
  x <- (1:dim(data)[1] - 1) / (dim(data)[1] - 1);
  axis(side=2, at=x, labels=rownames(data), las=2);
  x <- (1:dim(data)[2] - 1) / (dim(data)[2] - 1);
  axis(side=1, at=x, labels=colnames(data), las=1);
}


library(colorRamps)
library(gplots)
library(graphics)
library(RColorBrewer)

ts_months_max <- as.matrix(read.csv('./example.csv',sep='')
    col <- rev(brewer.pal(n = 11, name = "RdBu"))
           filled.contour(ts_months_max,plot.axes=matrix.axes(ts_months_max), main="Index 1",levels=seq(0,1,0.1),col = col)

introducir la descripción de la imagen aquí

When I call the last line to contour the values > 0.5, only one contour is displayed and in the legend.

 contour(ts_months_max, level=0.5,add=T)

introducir la descripción de la imagen aquí

May someone help me to solve this problem please?

Your suggestions would be greatly appreciated.

Thank you.