lattice

Produce single plot and conditioning plot in trellis graphics

时光怂恿深爱的人放手 提交于 2019-12-25 00:27:58
问题 Hi there: I'm playing around with the ``tips'' data set for a course that I'm teaching. I'd like to produce one .png file that has the plot of tip as a function of size on the top row of the plotting device (ideally in the center-top, of the window) and the bottom row being the conditioning plot of tip as a function of size grouped by a categorical variable recoded from the total_bill variable contained in the data set. I'm much more familiar with the ggplot2 environment, although I can't

Changing default colours of a lattice plot by factor

霸气de小男生 提交于 2019-12-24 17:43:12
问题 I have been able to create a 3D plot using the cloud function in lattice, however I do not know how to change the colour of points to a factor apart from the default setting of red and black. How to change points and add a regression to a cloudplot (using R)? this question addressed a similar point but I still do not know how to change the default colors. How can I achieve this? What I would like to do is change the colors of the points to grey and black for factor levels 1 and 2,

Adding marginal histograms (or boxplots) to xyplot using lattice

久未见 提交于 2019-12-24 11:27:40
问题 Similar to this question, I'd like to to add marginal histograms or boxplots to a xyplot or densityplot using lattice . Is there a way to replace the right and/or top axes with these plots instead? Something like: library(lattice) x <- rnorm(100) y <- rnorm(100) xyplot(x~y, x.top = histogram(~x), # desired y.right = bwplot(~y) # desired ) How could I do this? 回答1: Using ggplot2 with ggExtra works. library(ggplot2) library(ggExtra) p <- ggplot(cars, aes_string('speed', 'dist')) + geom_point()

rotating the grid to plot horizontal errors bars with Hmisc::xYplot in R

三世轮回 提交于 2019-12-23 18:31:12
问题 I'm using xYplot to plot my regressions results with error bars. However, xYplot only plots horizontal error bars, and I need vertical error bars. Looking around for a solution, I found this thread where someone asked roughly the same question. After some messages, the user who asked the question says that "I just discovered that using the xYplot (Hmisc) and rotating the grid viewport (and the labels etc) given me exactly what I need". So I looked around on how to rotate the grid and found

Obtaining midpoint values of grouped bars in lattice barchart function

只谈情不闲聊 提交于 2019-12-23 08:59:00
问题 I am trying to figure out how to determine the midpoint values of grouped bars, i.e. the actual X positions of the center of each bar. This is easily done in the base R barplot function, however I'd like to be able to do it in lattice 's barchart . My goal is to display the values of text column on top of the corresponding bar. The code below allows me to place the text on top of the bars as long as I do not do use subgroups. I have tried searching Internet for the solution but nothing seems

lattice, connect points only if the connection has a positive slope

断了今生、忘了曾经 提交于 2019-12-23 08:06:07
问题 is there a comfortable way to connect points only if the connection has a positive slope? (otherwise the function should behave exactly as xyplot(...)) library(lattice) dat <- data.frame(x=1:10,y=sample(1:10)) xyplot(y ~ x, data=dat, panel = function(x, y,...) { panel.xyplot(x, y, type="o",...) } ) so the result shoud be a plot like this, but without crossed lines: Thank you Christof 回答1: dat <- dat[order(dat[, "x"]),] dat$group <- cumsum(c(1, diff(dat$y) < 0)) xyplot(y ~ x, data = dat,

lattice, connect points only if the connection has a positive slope

落花浮王杯 提交于 2019-12-23 08:05:07
问题 is there a comfortable way to connect points only if the connection has a positive slope? (otherwise the function should behave exactly as xyplot(...)) library(lattice) dat <- data.frame(x=1:10,y=sample(1:10)) xyplot(y ~ x, data=dat, panel = function(x, y,...) { panel.xyplot(x, y, type="o",...) } ) so the result shoud be a plot like this, but without crossed lines: Thank you Christof 回答1: dat <- dat[order(dat[, "x"]),] dat$group <- cumsum(c(1, diff(dat$y) < 0)) xyplot(y ~ x, data = dat,

Plotting Point and Line plot in XYPLOT Lattice

喜你入骨 提交于 2019-12-23 04:56:07
问题 I need a guidance related to plotting. with lattice package.I am trying to plot xyplot(median + Temp + Rule1 + Rule3 ~ time | factor(name),data=v1,pch=19,grid=19,grid=TRUE,main="Time Series Analysis",xlab="Time",layout=c(1,1),points=TRUE,size=50,fill="transparent")) here Rule1,Rule2,Rule3 are categorical variable whereas median and temp are numerical my query is how can we show categorical plot as point plot and numerical variable as line plot in XYplot formatlattice Hence Expected Plot is

grid.arrange with John Fox's effects plots

末鹿安然 提交于 2019-12-23 01:58:42
问题 I'd like to combine multiple effect plots in one window with the effects package, but don't know if there is an easy way to do so. Here's an example that doesn't work: d1 <-data.frame(x1=rnorm(100,0:10),y1=rnorm(100,0:10),x2=rnorm(100,0:10),y2=rnorm(100,0:10)) require(effects) require(gridExtra) plot1 <- plot(allEffects(mod=lm(y1~x1,d1))) plot2 <- plot(allEffects(mod=lm(y2~x2,d1))) grid.arrange(plot1,plot2,ncol=2) 回答1: I think you need to collect the values of allEffects components and then

R: display values in levelplot stratified by a grouping variable

霸气de小男生 提交于 2019-12-22 18:32:29
问题 In this following example, I need to display the values for each of the cells in each of the panels stratified by the grouping variable class : library("lattice") x <- seq(pi/4, 5*pi, length.out=5) y <- seq(pi/4, 5*pi, length.out=5) r1 <- as.vector(sqrt(outer(x^2, y^2, "+"))) r2 <- as.vector(sqrt(outer(x^2, y^2, "/"))) grid1 <- grid2 <- expand.grid(x=x, y=y) grid1$z <- cos(r1^2)*exp(-r1/(pi^3)) grid2$z <- cos(r2^2)*exp(-r2/(pi^3)) grid <- rbind(grid1, grid2) grid$class <- c(rep("addition"