How to Change the Order of the Panels in Simple Lattice Graphs

How to change the order of the panels in simple Lattice graphs

I converted Temp to factor and got this:

Sample Image

You can temper with factor order like so:

levels(rate$Temp) <- c("12", "9", "18", "15") #custom factor order

rearranging panels in lattice xyplot

From the ?xyplot help page, under index.cond,

If index.cond is a list, it has to be as long as the number of conditioning variables, and the i-th component has to be a valid indexing vector for levels(g_i), where g_i is the i-th conditioning variable in the plot

So since you have two conditioning variables, you should have a list of length two. Each of your variables has two levels. I still don't understand how you are numbering these plots, but depending on how your factors are leveled, try some form of

index.cond = list(2:1, 2:1)
#or
index.cond = list(2:1, 1:2)

but using this along with as.table seems a bit odd.

Changing panel order in lattice plots within nlme

I think the easiest way to change the order of the panels is to change the order of the factor outside the plot call.

dat22 = augPred(fit.nlme3.10)
dat22$.groups = factor(dat22$.groups,
levels = c("Above:12", "Above:21", "Above:35", "Above:43", "Above:15",
"Above:23", "Above:32", "Above:41", "Above:13", "Above:24",
"Above:31", "Above:46", "Below:12", "Below:21", "Below:35",
"Below:43", "Below:15", "Below:23", "Below:32", "Below:41",
"Below:13", "Below:24", "Below:31", "Below:46"))
plot(dat22, layout = c(4,6), xlab="", ylab="", ylim=c(-200,2700))

To change the titles in each strip, you can set the factor.levels using strip.custom.

plot(dat22, layout = c(4,6), xlab="", ylab="", ylim=c(-200,2700), 
strip = strip.custom(factor.levels = c("M", "M", "M", "M", "FP", "FP", "FP", "FP", "P", "P",
"P", "P","M", "M", "M", "M", "FP", "FP", "FP", "FP", "P",
"P", "P", "P")))

This replaces the original names, though, and I wasn't entirely certain if you wanted to augment the names or change them entirely.

Altering the plot order for the factor variable in an xyplot using the lattice package

The solutions always seem so simple, in hindsight.

Issue 1: I had to use levels() and reorder() in the factor command, where X = the numeric factor I want to order SiteCode by.

xyplot(AvgSal ~ DayN | factor(SiteCode, levels(reorder(SiteCode, X),

Issue 2: Turned out to be very simple, once I knew what I was doing. Just had to 'turn off' strip, with the following getting rid of the title strip altogether.

strip = FALSE

In addition, I decided having the strip vertically aligned on the left would be nice:

strip = FALSE,
strip.left = strip.custom(horizontal = FALSE)

Index.cond does not rearrange the panels in lattice

"index.cond", as other arguments described in ?xyplot are either passed to the functions that create "trellis" objects or to the update methods. So, in this case, you can

create "graph1" by passing "index.cond" to histogram:

histogram(~ height | voice.part, data = singer, 
main = "Heights of Choral Singers by Voice Part",
index.cond = list(c(2, 4, 6, 8, 1, 3, 5, 7)))

, use update:

update(graph1, index.cond = list(c(2, 4, 6, 8, 1, 3, 5, 7)))

or use "[":

graph1[c(2, 4, 6, 8, 1, 3, 5, 7)]

How to specify the order of plots in a group of lattice xyplots?

To get the plotting order you expect, perhaps try adding as.table=TRUE to your call to xyplot().

From ?xyplot:

as.table:

A logical flag that controls the order in which panels should be displayed:
if FALSE (the default), panels are drawn left to right, bottom to top (as in
a graph); if TRUE, left to right, top to bottom (as in a table).

How to reorder this R lattice barchart manually?

Answer based on user20650's comments and other iterations

datm$male.Nij <- factor(datm$male.Nij, c("Sinus", "Arr/AHB", "Digoxin arr", "Furosemide arr"))

# http://stackoverflow.com/a/6359164/54964
library(lattice)
lvs = unique(dat$male.Nij) # for ordering facets
barchart(variable ~ value|group + factor(male.Nij, levels=rev(lvs)),
factor(male.Nij, levels=lvs),
groups=gender,
data=datm,
auto.key=list(space='right')
)

where the application of the first line and rev(lvs) are needed.
The behaviour is different in some other R systems, which reason is unknown.

How to change the order of the bars in accordance with the group variable in a barplot using lattice in R?

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 it back the other way by changing decreasing=F.

Controlling the number of panels in a lattice plot with R

Have a look at the layout parameter.

Maybe you want something like:

xyplot(Predicted_value + Actual_value ~ x_value | State_CD, data=dd, layout = c(4,5))


Related Topics



Leave a reply



Submit