levelplot

R - How to add legend title to levelplot saved to a variable?

回眸只為那壹抹淺笑 提交于 2019-12-07 12:16:39
问题 I would like to add the title for a legend in a levelplot graph saved to a variable. For example, this code works: library(lattice) library(grid) x = 1:10 y = rep(x,rep(10,10)) x = rep(x,rep(10)) z = x+y levelplot(z~x*y, colorkey=list(labels=list(cex=1,font=2,col="brown"),height=1,width=1.4),main=list('b',side=1,line=0.5)) trellis.focus("legend", side="right", clipp.off=TRUE, highlight=FALSE) grid.text(expression(m^3/m^3), 0.2, 0, hjust=0.5, vjust=1) trellis.unfocus() But this code, where the

Locking color key in levelplot in r

浪尽此生 提交于 2019-12-07 11:13:04
问题 I am using levelplots to display matrices and the plots are below. Though same col.regions are used for both the plots, the colour key is different. How can we lock (or set) the colour key for both level plots? I want the same colour key (0 to 60) for both plots. 回答1: Try setting the at and colorkey parameters. In my example, I use the rasterVis package, which just extends the lattice plotting functions for rasters, but it should not be necessary. I just wanted to use the BuRdTheme() function

R levelplot adjust axes

前提是你 提交于 2019-12-06 13:39:17
I want to plot the probability distribution function (PDF) as a heatmap in R using the levelplot function of the "lattice" package. I implemented PDF as a function and then generated the matrix for the levelplot using two vectors for the value ranges and the outer function. I want the axes to display the My issue is that am not able to add properly spaced tickmarks on the two axes displaying the two actual value ranges instead of the number of columns or rows, respectively. # PDF to plot heatmap P_RCAconst <- function(x,tt,D) { 1/sqrt(2*pi*D*tt)*1/x*exp(-(log(x) - 0.5*D*tt)^2/(2*D*tt)) } #

Plot specific point data on each layer in stack with rasterVis in R

江枫思渺然 提交于 2019-12-06 07:36:49
问题 I have 2 rasters stacked together: library(rasterVis) r1 <- raster(system.file("external/test.grd", package="raster")) r2 <- r1 / 2 r.stack <- stack(r1, r2) Since I would like to highlight some areas later for each specific layer in the stack, I create two point datasets based on the raster values: pts1 <- rasterToPoints(r1, spatial=T) idx <- which(as.data.frame(pts1)[, 1] >= 400) pts1 <- pts1[idx, 1] pts2 <- rasterToPoints(r2, spatial=T) idx <- which(as.data.frame(pts2)[, 1] >= 400) pts2 <-

Using patterns in addition/instead of background colors in lattice plots

不打扰是莪最后的温柔 提交于 2019-12-06 02:36:53
问题 I am using level plots from the R lattice package. My resulting plots look like the one shown below. My problem now is that I need to generate a black and white version for printing. Is there a way to change the colors to grayscale and give the rectangles a background pattern so the the red once are distinguishable from the blue ones? For example, dots or diagonal dashes come to mind. Thanks! 回答1: I found a way to manually draw into the levelplot panel and to draw a diagonal fill pattern over

Relassify continuous raster data into binned classes with discrete colors

[亡魂溺海] 提交于 2019-12-06 01:27:06
问题 I would like to: Reclassify the raster ras into nine classes using reclassify Provide a colorkey with values written beside each colour (see sample plot below). The colorkey should not be split, as in the sample plot, but rather shown as a single colour ramp with 9 colours. Display the data using levelplot function (this I can do) Thanks for your help. AEZ library(rasterVis) Please use these colors: col <- colorRampPalette(c("yellow4", "yellow", "orange", "red3", "darkred")) levelplot

Add Different Labels to Secondary X-Axis of Levelplot in Lattice in R

喜欢而已 提交于 2019-12-06 01:05:22
I've managed to label the secondary X-axis in a levelplot using scale=list((alternating=3)) as solved by @KoenV here: How to Add Labels to Top X-Axis of Levelplot in Lattice Package Now this duplicates the primary X-axis labels onto the secondary X-axis as can be seen by running the code below. However, I need to add different labels to the secondary X-axis. Does anyone know how to do this? In the example below I would like to have 'hor' as the primary X-axis labels and 'hor2' as the secondary X-axis labels. library(lattice) #Build the horizontal and vertical axis information hor <- c("214",

Use layout function within levelplot

岁酱吖の 提交于 2019-12-05 03:41:20
问题 I am doing mapping in R and found the very useful levelplot function in rasterVis package. I will like to display multiple plots in a window. However, par(mfcol) does not fit within lattice . I found layout function very useful in my case but it fails to perform what I want to do. Here is my code: s <- stack(Precip_DJF1, Precip_DJF2, Precip_DJF3, Precip_DJF4, Precip_DJF5, Precip_DJF6) levelplot(s, layout(matrix(c(1, 2, 0, 3, 4, 5), 2, 3)), at=seq(floor(3.81393), ceiling(23.06363), length.out

Raster map with discrete color scale for negative and positive values R

不打扰是莪最后的温柔 提交于 2019-12-04 13:39:51
问题 I have two dataframes which I will like to map. The dfs have the same xy coordinates and I need a single colorbar with a visible discrete color scale for both dfs like the one shown here. I would like the colors in the colorkey to match the self-defined breaks. a more general solution that can be applied outside this example is much appreciated The RdYIBu color palette from the RcolorBrewer package is what I am after. My code so far: library(rasterVis) ras1 <- raster(nrow=10,ncol=10) set.seed

Plot specific point data on each layer in stack with rasterVis in R

人走茶凉 提交于 2019-12-04 12:25:18
I have 2 rasters stacked together: library(rasterVis) r1 <- raster(system.file("external/test.grd", package="raster")) r2 <- r1 / 2 r.stack <- stack(r1, r2) Since I would like to highlight some areas later for each specific layer in the stack, I create two point datasets based on the raster values: pts1 <- rasterToPoints(r1, spatial=T) idx <- which(as.data.frame(pts1)[, 1] >= 400) pts1 <- pts1[idx, 1] pts2 <- rasterToPoints(r2, spatial=T) idx <- which(as.data.frame(pts2)[, 1] >= 400) pts2 <- pts2[idx, 1] Now, I would like to plot the raster stack with levelplot from rasterVis in R. I would