Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Place all axis labels at left and bottom in R lattice xyplot

Tags:

r

lattice

I would like to alter the default xyplot setting where the axis labels alternate by panel.

xyplot(yield~N | P+K, data=npk)

enter image description here

I realize that it is intentional to avoid overlaps of axis extremes on neighboring panels, but for categorical x-axis labels as shown above, it is not necessary and looks odd for publication.

Is there a way to put all axis labels on the same side as shown below (which I edited in a graphics program)?

enter image description here

like image 498
emudrak Avatar asked Sep 10 '25 02:09

emudrak


1 Answers

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 a list. The default for alternating is TRUE and switching it to FALSE will do the trick:

xyplot(yield~N | P+K, data=npk, scales=list(alternating=FALSE))

enter image description here

You can also enter a numeric value for this parameter to determine what side the labels should go on:

xyplot(yield~N | P+K, data=npk, scales=list(alternating=1))
xyplot(yield~N | P+K, data=npk, scales=list(alternating=2))

You can pass it multiple parameters to have each panel behave differently:

xyplot(yield~N | P+K, data=npk, scales=list(alternating=c(1,0))) 

Default here is c(1,2)

like image 145
emudrak Avatar answered Sep 12 '25 18:09

emudrak