简体   繁体   中英

filled contour plot in R

I am trying to generate a filled contour plot in R. My data labels x and y are length 20 vectors, and my z matrix is 20 by 20. The following is my code, with the filled.contour command copied directly from the r help(filled.contour) file, just with extraneous parameters removed:

x <- seq(1,5)
y <- seq(1,5)
cells <- c(1,4,9,16,25,1,4,9,16,25,1,4,9,16,25,1,4,9,16,25,1,4,9,16,25)
z <- matrix(cells,nrow=5,ncol=5,byrow=TRUE)
filled.contour(x,y,z,nlevels = 20,col = cm.colors(19))

You have to remove col =color.palette(length(levels) - 1) . You have to know that in R manuals, the line that is under Usage just shows which parameters are available and next to it the default parameter. Which does not necessarily mean you can write it exactly the same way. So if you leave these parameter, it will automatically take the value that is stated there.

For examples you should check the Examples section, which is usually quite rich.

EDIT

To get 19 colors you have to write

filled.contour(x,y,z,nlevels = 20,col =cm.colors(19))

cm.colors is a function that returns n colors. color.palette can not do that for you because it is not a function but a parameter for filled.contour.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM