lattice

Adding a background image to a levelplot

我们两清 提交于 2019-12-11 19:45:10
问题 I'd like to make a levelplot which has a background image. The following code promts the error message Error in rasterImage(image, x[1], y[1], x[length(x)], y[length(y)]) : plot.new has not been called yet - apparently rasterImage does not recognize printed levelplot object as a plot. What's the appropriate method instead of rasterImage ? library("png") library("lattice") library("latticeExtra") MyFunction <- function(x,y){ return( dnorm(sqrt(x^2+y^2)) ) } meshstep <- 0.2 x<- seq(-20,20

Generate multiple lattice plots on a grid using lapply in R

≡放荡痞女 提交于 2019-12-11 19:19:06
问题 How do plot multiple lattice plots onto a single lattice plot where the plots are generated using an lapply function? The following is a demonstration of what I have tried so far using the built in mtcars dataset. require(lattice) response <- c("cyl","disp","hp","drat") par(mfrow=c(2,2)) lapply(response, function(variable) { print(xyplot(mtcars$mpg ~ mtcars[variable])) }) This produces the plots desired. However it seems to be ignoring the par(mfrow=c(2,2)) instruction and plotting each plot

Lattice xyplot does not show all levels of factor on Y axis: incomplete plot

戏子无情 提交于 2019-12-11 14:31:26
问题 I use xyplot() from the Lattice to plot arrows defined by a dataframe with 3 columns: posi (numerical), from (character), to (character). The problem: On occasion, the arrows go beyond the scale of the plot. In other words, the plot window is not big enough to visualize all the data. I tried adding the factor levels explicitly, to no avail. It seems that if the more extreme levels (e.g. "D") are not present in the factor "df$from", those are not counted to draw the plot window. I looked at

r- Add error bars to different groups in xyplot

旧城冷巷雨未停 提交于 2019-12-11 12:17:57
问题 I'm quite new to R, so I hope you guys can help me out with this problem. I tried to look for other posts with similar questions, but wasn't able to find any. This is how my representative data set is constructed: library(lattice) data(Theoph) DF <- Theoph DF$Time <- rep(c(0,0.25,0.5,1,2,4,5,7,9,12,24), times=12) DF$group[DF$Subject==1|DF$Subject==2|DF$Subject==3] <- "A" DF$group[DF$Subject==4|DF$Subject==5|DF$Subject==6] <- "B" DF$group[DF$Subject==7|DF$Subject==8|DF$Subject==9] <- "C" DF

Lattice's `panel.rug` produces different line length with wide plot

家住魔仙堡 提交于 2019-12-11 10:31:13
问题 When producing a wide plot in lattice with margins that include panel.rug() , the length of the lines in rugged margins is longer in the y-axis than x-axis: library(lattice) png(width=800, height=400) xyplot(Fertility ~ Education, swiss, panel = function(x, y,...) { panel.xyplot(x, y, col=1, pch=16) panel.rug(x, y, col=1, end= ...)}) dev.off() I would like those rug lines in x- and y-axes to be the same length regardless of the shape of a plot (note: right now the rug lines will only be the

Different scales of multipanel plots using lattice package in R

天涯浪子 提交于 2019-12-11 10:11:47
问题 I followed the script of agstudy in this page and produced panel of box-plots like this Figure But the I have a different kind of problem; the ranges of the variables are different. Therefore, plots except for 'moisture' are not properly scaled. How can I force lattice to scale the plots as per their own range? Thanks in advance. 回答1: With lattice, you can make each panel have it's own scales with the "relation" property. The "free" option lets all of the panels be independent. See ?xyplot

Rearrange x-axis of hour when plotting

寵の児 提交于 2019-12-11 08:37:19
问题 I have a record of activities by six groups of people which looks like this: grp hour intensity 1 0 0.048672391 2 0 0.264547556 3 0 0.052459840 4 0 0.078953270 5 0 0.239357060 6 0 0.078163513 1 1 0.029673036 2 1 0.128206479 3 1 0.030184495 4 1 0.076848385 5 1 0.061325717 6 1 0.039264419 1 2 0.020177515 2 2 0.063696611 3 2 0.023759638 4 2 0.047865380 5 2 0.030226285 6 2 0.021652375 ... and I make a multiple-line graph out of it: library(lattice) xyplot(intensity ~ hour, groups= grp, type= 'l',

shading within xy curve plot in R

我的梦境 提交于 2019-12-11 08:26:09
问题 I have data similar to following: X <- 1:20 B <- c(1,4,6,3,1, 4, 5,8,8,6,3,2,1, 1,5,7,8,6,4,2) C <- B + 4 myd <- data.frame (X, B, C) I want to shade with different color within the curve. Please note the boundries color filling in x region 1 = 1 to 6 region 2 = 6 to 16 region 3 = 16 to 20 回答1: Here is a solution with ggplot2. library(ggplot2) library(reshape2) d <- melt(myd, id.vars="X") d <- rbind( transform( d[ 0 <= d$X & d$X <= 6, ], interval=1 ), transform( d[ 6 <= d$X & d$X <= 16, ],

R lattice plots and postscript [duplicate]

為{幸葍}努か 提交于 2019-12-11 07:59:21
问题 This question already has an answer here : Closed 7 years ago . Possible Duplicate: Generate multiple graphics from within an R function I have tried to make an eps-file of a lattice plot. The .eps-file is created, but the plot seem to be blank (using 'gv'). I have been searching the inter-net for a solution, but without luck. My code is as follows: mydf <- data.frame(col1=c(1,1,2,2,3), col2=c(1,2,1,2,1), col3=rnorm(5)) library(lattice) filename <- "myfile.eps" postscript(file = filename,

Make color palette of discretized values for a continuous variable (lattice levelplot)

我与影子孤独终老i 提交于 2019-12-11 07:29:18
问题 Following up on this question, I want to make a levelplot heat map and color each cell according to the variable p.value in my data frame. I would like to have the cells colored in such way that there are only 3 colors (discretized color palette for continuous variable): white for p.values >0.05 red for p.values <0.05 and >0.01 dark red for p.values <0.01 So far this is my MWE. set.seed(150) pv.df <- data.frame(compound=rep(LETTERS[1:8], each=3), comparison=rep(c("a/b","b/c","a/c"), 8), p