you could try with gtable library(gtable) library(grid) grid.expr <- function(labels, ..., width=NULL, heights=NULL, margin=unit(0.5,"line")){ gl <- lapply(labels, textGrob, ...) if(is.null(heights)) heights <- do.call(unit.c, lapply(gl, grobHeight)) + margin widths <- do.call(max, lapply(gl, grobWidth)) gt <- gtable_matrix("table", grobs = matrix(gl,ncol=1), widths=widths, heights=heights) grid.draw(gt) } grid.newpage() grid.expr(LETTERS[1:5], heights=unit(1:5,"line")) ...

You can use the scales argument in the dotplot function to indicate that you'd like the y-axis to scale freely. This will then include only those levels that are present in each panel: dotplot(iso2c~value | region, data=ds, groups=year,pch=19, col="dark blue",cex=1.3,ylab="country",layout=c(1,2), scales = list(y = list(relation = "free"))) ...

While checking to make sure I didn't duplicate a question, I tried some new search terms and found the solution buried in the lengthy xyplot help file. There is a parameter called “scales” that itself has a bunch of parameters that you can specify, and it has to be in...

r,panel,bar-chart,data-visualization,lattice

You need to create a custom panel function that takes into account the box.width of your bars. After some experimentation I came up with this, which seems to work: panel = function(x, y, ...) { dots <- list(...) br <- dots$box.ratio panel.barchart(x, y, ...) panel.abline(h = seq_along(x) - 0.5*(br/(br+1)), col="orange",...

As mentioned, ordering of groups in R graphics is usually determined by the ordering of the factor variable. So, you can reorder your factors with factor and its levels argument. library(lattice) barchart(~irr_area | factor(state) + factor(irr_source), group=factor(year, levels=sort(unique(year), decreasing=T)), # change the order of years data=irr_atlas, auto.key=list(space="right")) You can switch...

You need the xlab argument: library(lattice) Gender <- rep(c(1,2),50) barchart(equal.count(Gender), horizontal=FALSE, xlab = c("Male","Female")) ...

The basic strategy you want is to first come up with a character vector, where each element in the vector is the text you want on a particular panel. Then you can use the panel.number() function to chose a different element of the character vector for each panel. Here is...

I've been thinking about this problem for a while but i've been very busy so I didn't have much time to work on it till now. I understand better what your original question was. By default Lattice does not like to stack the points on top of the lines in...

I don't quite see how your plot matches with your code. But this may work for you. Define col within panel.groups and reference that indexed by group.number in panel.segments. library(lattice) myColours=1:7 time<- rnorm(50,5,2) death.count<- rnorm(50,-0.25,0.25) Inoc.size<-rep(c("A","B"),times=25) data<-data.frame( time,death.count, Inoc.size) xyplot(death.count~time, data, groups=Inoc.size,#ylim=c(0,-0.5), xlab = list("Time - h", cex=1.5), ylab =...

after some (small) modifications, I have used this script xyplot(foo ~ bar | thing, data = d.f, panel = function(x,y){ xx <- do.breaks(range(x), 49) mod <- loess(y~x) yy <- predict(mod, newdata = data.frame(foo=xx)) panel.xyplot(x,y) panel.lines(x=xx, y= yy) }) I have changed the number of points because there was some warning...

The following prints a lattice xyplot to a png. It is a minimal example, done as a variation around rinside_sample11.cpp. #include <RInside.h> // for the embedded R via RInside #include <unistd.h> int main(int argc, char *argv[]) { // create an embedded R instance RInside R(argc, argv); // evaluate an R...

Rather than passing a col= parameter to barchart, lattice much prefers if you change the par.settings. In this case. the color of the bars is determined by superpose.polygon because you have different groups of ratings. This should do what you want data<-data.frame( service = c("renew_patent", "apply_benefit", "apply_employment_tribunal"), rating_1 = c(0,...

A translation of your first example would be xyplot(x~seq_along(x), df, scales=list(y=list(at=df$x[3], labels=df$Num[3]))) Read mode about the scales= parameter in the ?xyplot help page....

With lattice plotting functions, use scales=list(cex=1.5) to set cex for tick labels along both axes. To specify different cex values for x- and y- axes, do something like this: library(lattice) xyplot(mpg~disp, data=mtcars, scales=list(tck=c(1,0), x=list(cex=1.2), y=list(cex=1.5))) ...

Instead of using grid.arrange, you may rearrange your data to be able to use the formula method of x in levelplot. This allows you to easily create a plot with different panels based on a grouping variable g, with a common scale. Here g ('L1') corresponds to the different matrices....

Assuming I switch things around so you actually have a "dog" panel, here's how you can conditionally change the panel function xyplot(Y~Z|X, data=data, type=c("smooth","p"), cex=1.4, col="black", panel = function(..., type) { grpname <- dimnames(trellis.last.object())[[1]][packet.number()] if(grpname == "dog") { panel.xyplot(..., type=setdiff(type,"smooth")) } else { panel.xyplot(..., type=type) } }, scales=list( x=list(rot=45, cex=0.9),...

With lattice, this should work xyplot(Gene_exp ~ Time| Gene_name, Data, slopeInt=slopeInt, jitter.data = T, panel = function(..., slopeInt){ panel.xyplot(...) grp <- trellis.last.object()$condlevels[[1]][which.packet()] panel.abline(a = slopeInt[grp,1], b = slopeInt[grp,2]) }, layout = c(4, 2) ) using set.seed(15) before generating the sample data results in the following plot The "trick" here is...

The problem with doing what you want easily is that the ranef() results don't include the information that you want, and the dotplot.ranef.merMod() method is a bit too hard-coded to modify easily ... I'm going to show a ggplot solution instead. If you insist on a lattice solution, try examining...

One way is with grid.text, referring to the desired location with npc coordinates, where the lower left corner is (0, 0), and the upper right is (1, 1). library(grid) xyplot(X~Y|Z, data=df1, groups=n, panel=function(x, y,...) { panel.xyplot(x,y,...) grid.text(MyText[panel.number()], unit(0.05, 'npc'), unit(0.95, 'npc')) }, ylab = expression(paste(delta, ""^"15","N")), xlab = expression(paste(delta, ""^"13","C")),...

r,ggplot2,maps,lattice,shapefile

OK, I managed to resolve this issue by changing the aesthetic group parameter found on page 11 of the ggplot2 manual: http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf The correct parameter is "group" and not the factor that is used to group the plots. The correct ggplot code: ggplot(data = wtrl_f, # the input data aes(x...

1) To break apart the two visits for subject 2, you can make a new grouping variable simply by pasting ID and VISITNUM within the groups= argument like so: xyplot(OBS ~ TIME, groups = paste(ID,VISITNUM) data = DF, type = 'b', ) To only see one group use the subset...

The pairs() function gets you close, but if you want just the six panels as shown in your layout matrix, then you might have to construct it by hand. You can construct the chart using grid, or ggplot and gtable. Here is a ggplot / gtable version. The script works...

The essence of your question, it seems, is how to produce a contour plot in ggplot with discrete filled contours, rather than continuous contours as you would get using the conventional geom_tile(...) approach. Here is one way. x<-seq(1,11,.03) # note finer grid y<-seq(1,11,.03) xyz.func<-function(x,y) {-10.4+6.53*x+6.53*y-0.167*x^2-0.167*y^2+0.0500*x*y} gg <- expand.grid(x=x,y=y) gg$z <-...

## even data.freq.even <- structure(list(`Strongly Disagree` = c(2L, 1L), `Moderate Disagree` = 1:2, `Slightly Disagree` = c(3L, 1L), `Slightly Agree` = c(1L, 5L), `Moderate Agree` = 4:5, `Strongly Agree` = c(9L, 6L), Group = c("Experimental group", "Control group")), .Names = c("Strongly Disagree", "Moderate Disagree", "Slightly Disagree", "Slightly Agree", "Moderate Agree",...

Try this Load lackages, download when necessary kpacks <- c('raster', 'ggplot2', 'reshape2', 'lubridate') new.packs <- kpacks[!(kpacks %in% installed.packages()[,"Package"])] if(length(new.packs)) install.packages(new.packs) lapply(kpacks, require, character.only=T) remove(kpacks, new.packs) d <- read.table(text=readClipboard(), sep = '\t', header=TRUE) # or copy and paste the data from above coords <- read.table(text=readClipboard(), sep = '\t', header=TRUE, quote =...

This is a late answer, but part of your problem is that legend() is base graphics and xyplot is from lattice and these two do not mix well. You can just use the auto.key=T argument to add a key. Here is a somewhat cleaned up version of your code: xyplot(FFM~time...

As mentioned in comments above, your third call to histogram() was very close. You just needed to write darg instead of dargs. Here's an example to show that darg does indeed, as documented in ?panel.densityplot, give you control over the smoothing parameters: library(gridExtra) ## For grid.arrange() library(lattice) df <- data.frame(y...

I got help and have a solution now: insitu <- read.table("insitu.txt",header=TRUE,colClasses=c("Date","numeric")) est <- read.table("estimated.txt",header=TRUE,colClasses=c("Date","numeric")) insitu.plot <- xyplot(insitu~date_fname,data=insitu,type="l", panel=function(x,y,...){panel.grid(); panel.xyplot(x,y,...)},xlab=list(label="Date",cex=2)) est.plot <- xyplot(estimated~date,data=est,panel=panel.bwplot,horizontal=FALSE) both <- insitu.plot+est.plot...

Yes, yaxs doesn't work in lattice. See here for how it is handled. However, I got this to work by skipping the prepanel and calculating the ylim directly in the barchart call. library(lattice) order=data.frame(Order=rep(paste0("order",1:4),times=2), Area=rep(paste0("Area ",1:2),each=4), Count=c(224122,2091,45867,32816,71548,309,22564,10686), Stdev=c(37263,253,4450,4563,2046,25,315,987)) panel.err=function(x, y, subscripts, groups, Stdev, box.ratio, ...){ d <- 1/(nlevels(groups)+nlevels(groups)/box.ratio) g <-...

Lattice is going to create a strip for each conditioning variable. If you want just one strip, try conditioning on the interaction. For example wireframe(pred~Sepal.Width+Petal.Width|interaction(Species,Petal.Length), pd, drape=FALSE,scale=list(arrows=FALSE), subset=(Species=="setosa"), layout=c(3,3)) which gives You can create the interaction ahead of time and customize the levels if you like with whatever description you...

You got most of the code right. It would be better to use the time (tiempo) variable as an id variable in your melt call This will ensure the lengths of the data match up. library(reshape2) #This is faster version of reshape df.m <- melt(df.matias, id.var="Tiempo") #I stored your data...

r,ggplot2,lattice,kernel-density

You could do it with geom_line: m <- ggplot(NULL, aes(x=bkde(movies$votes)$x,y=bkde(movies$votes)$y)) + geom_line() print(m) If you were doing t with lattice::densityplot, you could probably add some of the values to the drags-list: darg list of arguments to be passed to the density function. Typically, this should be a list with zero...

r,powerpoint,lattice,grayscale,reporters

it is OK when using trellis.par.set. See below: library(ReporteRs) library(lattice) p <- xyplot(decrease ~ treatment, OrchardSprays, groups = rowpos, auto.key =list(space = "right")) ltheme <- standard.theme(color = FALSE) doc = pptx("Test") doc = addSlide(doc, "Title and Content") doc = addPlot(doc, fun = { trellis.par.set(ltheme) print(p) }) writeDoc(doc, "test.pptx") ...

add between to your auto.key list. For example, auto.key=list(space="top", columns=6, text.width=0, cex=0.5, pch=20,between=.5), or even between=0....

I think this does it. I calculated the max and min of the x-values within groups of the "y" values, and then used the lattice-lsegments functions dotplot(iso2c~value, groups=year, data=ds, panel = function(x,y,...) { x0=sapply( split(x,y), min) y0=as.numeric(unique(y) )+.1 x1=sapply( split(x,y) ,max) y1=as.numeric(unique(y)) +.1 panel.dotplot(x, y,...) lsegments(x0,y0,x1,y1) } , pch=19,col="dark blue",cex=1.3,ylab="country")...

If you want to change colors of points consistently across panels, I suggested you do that via the more standard groups= argument. I would change these two linesin your compareCats function cols2 <- factor(cols2, levels=cols) # no need to attach to data p <- lattice::xyplot(as.formula(args$formula), groups=cols2, data = eval(args$data), ...,...

library(lattice) xyplot(y ~ x | group, dta, layout=c(4,2), as.table = TRUE) As suggested by @BenBarnes, as.table = TRUE keeps the order of the facets. ...

The problem is match up the current panel data to the listaPM data. Because you are doing different sub-setting in each of the calls, it's difficult to use which.panel() to match up the data sets. There is an undocumented feature which allows you to get the conditioning variable names to...

dat <- dat[order(dat[, "x"]),] dat$group <- cumsum(c(1, diff(dat$y) < 0)) xyplot(y ~ x, data = dat, groups = group, panel = function(x, y,...) { panel.xyplot(x, y, type = "o", col = trellis.par.get("plot.line")$col, ...) } ) ...

Here is an example to get started on the left graph using base graphics (there are xspline functions for grid graphics as well if you want to use those, I don't know how to incorporate them with ggplot2, but lattice probably would not be too hard): plot.new() par(mar=c(0,0,0,0)+.1) plot.window(xlim=c(0,3), ylim=c(0,8))...

Having thought about this a bit more since my previous answer, I've come up with a simpler way of producing multipanel (if appropriate) fanplots, overlaid on a levelplot, as shown in the Wikipedia Fan chart page. This approach works with a data.frame that has two independent variables and zero or...

If I understand this correctly, what you wish to do is have the weekends not appear in the plot at all. One way to do this is to make another vector which is the order in which you want close plotted - a vector that does not include weekends. Assuming...

There is a lattice option called skip.boundary.labels. From the documentation under ?lattice.options: skip.boundary.labels Numeric scalar between 0 and 1. Tick marks that are too close to the limits are not drawn unless explicitly requested. The limits are contracted by this proportion, and anything outside is skipped. The default value of...

The general answer will be to use HH::ancovaplot() directly (rather than implicitly via HH::ancova()) along with latticeExtra's handy layer() function and overloaded + operator. I'll leave it to you to work out the fiddly details required to make it look exactly how you want it to. ancovaplot(Sodium ~ Calories *...

May be you can try ind <- which.min(H$perc) label1 <- paste0("H difference ", H$diff[ind], "% change count") label2 <- paste('X2 value', H$X2[ind]) xyplot(X8+X9+X10~X1,H,type=c('p','l','g'), col = c('yellow', 'green', 'blue','red'), ylab='Count',layout=c(3, 1), xlab=paste(label1, label2, sep=", ")) Update If you have multiple datasets, create a function labelfn <- function(dat, Col1, Col2, diffCol){ args...

Here is a general way to do it using some fake data. You will need to tweak this to make sure the names are as you like, library(reshape) library(mgcv) library(lattice) X1<-rnorm(100) # Make some fake data X2<-rnorm(100) X3<-rnorm(100) Y<-rnorm(100) Mod<-gam(Y~s(X1,bs="cr")+s(X2,bs="cr")+s(X3, bs="cr")) # make a model Z<- predict(Mod,type="terms", se.fit=T) #Z is...

Josh O'Brien points to the answer in his comments, and Paul Murrell's "locndimn" vignette (run vignette("locdimn") provides the details. A quantity like unit(5, "native") has one meaning if refers to a location in the coordinate system, and a different meaning if it refers to a dimension. Murrell's rule is that...

You can pass lists to the zlab, xlab and ylab arguments of wireframe. One component of these lists can be rot, which specifies in degrees the amount by which axis labels should be rotated. So far, I have only been able to "align" the labels with the axes by trial...

The problem is that you have missing data (NA) values in this data set. The panel.linejoin() calls mean() over the observations at each x and if there are NA vales, by default the mean will be NA and then a line won't be drawn. To change that, you can specify...

This happens because you specified the x axis scale with scales = list(x = list(at = 5:15)), but you didn't actually change the breakpoints. It happens in the default case as well: the default axis labels are integers, but the default breakpoints are determined programmatically and are not necessarily integers...

r,plot,panel,histogram,lattice

Here is the lattice version. Essentially you define a vector of colors, which I did outside the histogram() function. In the histogram() function you use a panel.function which will allow you to make each panel look different. You call panel.histogram and tell it to pick a color based on packet.number()....

The problem is because c doesn't have a dim attribute, like most xts objects do, and how many xts functions expect xts objects to have. Set the dim attribute and everything's okay. dim(c) <- c(length(c),1) xyplot(c~a) ...

First of all, what's with assign() in the graph1/graph2 functions? That seems completely unnecessary. So just change those to graph1 <- function(df) {xyplot (deltaxz ~ dates | SPEC, data=df, type=c("p","g"), col=c("black"), layout=c(1,3))} graph2 <- function(df) {xyplot (1/deltaxz ~ dates | SPEC, data=df, type=c("p","g"), col=c("red"), layout=c(1,3))} and secondly, the d_ply is...

I don't see anything elegant in heatmap or lattice::levelplot. Maybe someone knows how in ggplot. Here is a brute force proof-of-concept: d=data.frame(p1=rep(LETTERS[1:2],times=2,each=2), p2=rep(LETTERS[4:5],times=4), value=c(.2,.4,.56,.32,.7,.16,.12,.71), group=rep(c("A1","B1"),each=4)) x=as.numeric(d$p1) y=as.numeric(d$p2) plot(1,xlim=c(1,length(unique(x))+1),ylim=c(1,length(unique(y))+1), type="n",bty="n",xaxt="n",yaxt="n",xlab="",ylab="") for(i in 1:nrow(d)) { if(d$group[i]=="A1")...

I fixed this error by upgrading to R 3.2.

For each value of type, you'll need to construct a custom panel function. Fortunately, if you model the functions closely on existing lattice code (starting out by having a look at panel.xyplot), that shouldn't be too hard. For example, the two custom panel functions below include many lines of code...

For some reason segplot doesn't seem to respect the groups= parameter like most lattice plots do. Here's kind of a messy work around with the first step being generating your grouping variable df$group<-with(df, ifelse(lower>1, "superior", ifelse(upper<1, "inferior","contain"))) segplot(reorder(factor(geno), rd) ~ lower + upper, data = df, groups=group, xlim=c(-1, 2.5), draw.bands...

I solved my problem, thanks to @josh-obrien. Now, when the graphic title is longer than 70 characters it is wrapped to 65 characters wide version. library(HH) ppi <- 150 jpeg("ssb_%02d.jpg", width=7*ppi, height=4*ppi, res=ppi) for(i in 1:2){ if(stri_length(items[i,])>70){ graphic.title <- paste(strwrap(items[i,], width = 65), collapse="\n") } else { graphic.title <- items[i,]...

r,for-loop,plot,lattice,lapply

This is in the R-FAQ. Need a print statement around grid graphics (lattice or ggplot) when used inside a function, and the for loop is a function: # Needed require(data.table) # before defining the object. pdf() # pdf is a multipage device. for (i in 3:5) { # generate a...

I think you want the groups to be the interaction of learner and momentum: xyplot(rmse ~ epochs, data=data, groups = interaction(learner,momentum, sep=" : ", drop=TRUE), type = "l", auto.key = list(space = "right", points = FALSE, lines = TRUE)) (Note that we don't need to specify data$learner, etc, as the...

Lattice allows you to specify the number of columns and rows for the plots which then spill over onto adjacent pages if a multi-page device is used: pdf("nine.pdf", onefile=TRUE, paper="special") wireframe(pred~Sepal.Width+Petal.Width|interaction(Species,Petal.Length), pd, drape=FALSE,scale=list(arrows=FALSE), subset=(Species=="setosa"), layout=c(1,1,9)) dev.off() On the console device they create new plots which stack up in the plot...

By default, time series plots in R use type = "l", which means that you get a line but no point characters. To get both, you can change your type to "b". xyplot(a1, col = "red", pch = 2, type = "b") This yields: The same logic applies to the...

You need to specify the order of the levels in the data itself, then barchart will do what you want. One option would be to run code like: data$service <- factor(data$service, levels=unique( as.character(data$service) ) ) before calling barchart....

Axis limits for xyplot are calculated in the extend.limits function. This function isn't exported from the lattice package, so to see it, type lattice:::extend.limits. Concerning a numeric vector, this function is passed the range of values from the corresponding data (c(1, 10) in this example). The final limits are calculated...

Thanks to Deepayan Sarkar, this question was solved: library(HH) library(latticeExtra) ppi <- 150 jpeg("ssb_%02d.jpg", width=7*ppi, height=4*ppi, res=ppi) plot_obj <- likert(Grup ~ . | Grup, data = ssb, as.percent = TRUE, positive.order = TRUE, main="", xlab=list(label="Percent", cex=1.1), ylab="", ylab.right = list("Subjects per group", cex=1.1), scales = list(y = list(relation = "free",...

Because mtcars$gear is of class "numeric", you plot is using the "shingled" strip style associated with numeric conditioning variables. It sounds like you'd rather gear number be treated as a categorical variable, so you should convert it to a "factor" before conditioning on it. Here's what I would do: gearFac...