[R] Lattice: merged strips?

Mike Lawrence Mike.Lawrence at dal.ca
Sat Jul 12 03:16:39 CEST 2008


Aha! With the help of Deepayan's ever-insightful hints, I was able to  
do exactly what I wanted:

dotplot(
	variety ~ yield | site * year
	, data = barley
	, subset = (site %in% c("Grand Rapids", "Duluth"))
	, layout=c(4, 1)
	, scales=list(
		alternating = F
		, tck  =c(1, 0)
		, x = list(at=c(20, 30))
	)
	, strip = function(
		which.given
		, which.panel
		, var.name
		, factor.levels
		, ...
		){
		if(which.given == 1){
			strip.default(
				which.given = which.given
				, which.panel = which.panel
				, var.name = var.name
				, factor.levels = factor.levels
				, ...
			)
		}else{
			if(which.panel[1] == 1){
				panel.rect(0, 0.5, 1, 1, col = "grey", border = "transparent")
				panel.lines(x = c(0, 0), y=c(0, 1), col='black')
				panel.lines(x = c(0, 1), y=c(1, 1), col='black')
			}
			if(which.panel[1] == 2){
				panel.rect(0, 0.5, 1, 1, col = "grey", border = "transparent")
				panel.lines(x = c(0, 1), y=c(1, 1), col='black')
				panel.lines(x = c(1, 1), y=c(1, 0), col='black')
				panel.text(0, 0.75, labels = factor.levels[which.panel[2]])
			}
		}
	}
)



On 11-Jul-08, at 8:52 PM, Deepayan Sarkar wrote:

> On 7/10/08, Mike Lawrence <Mike.Lawrence at dal.ca> wrote:
>> As I understand it, Duncan MacKay's solution involves simply  
>> pasting the
>> factors together, as in:
>>
>> |_AX_|_AY_|_BX_|_BY_|
>>
>> Which isn't quite as aesthetically pleasing as what I I'm looking  
>> for:
>>
>> |___A___|___B___|
>> |_X_|_Y_|_X_|_Y_|
>>
>> Any further suggestions?
>
> There is no easy way, especially if you want a general solution, but
> for your specific example, here is a possible starting point:
>
>
> dotplot(variety ~ yield | site * year, data = barley,
>        subset = (site %in% c("Grand Rapids", "Duluth")),
>        strip = function(which.given, which.panel,
>                         var.name, factor.levels, ...) {
>            str(list(which.given = which.given,
>                     which.panel = which.panel,
>                     var.name = var.name,
>                     factor.levels = factor.levels, ...))
>            if (which.given == 1)
>                strip.default(which.given = which.given,
>                              which.panel = which.panel,
>                              var.name = var.name,
>                              factor.levels = factor.levels, ...)
>            else {
>                panel.rect(0, 0.5, 1, 1, col = "#ccffcc",
>                           border = "transparent")
>                if (which.panel[1] == 2)
>                    panel.text(0, 0.75,
>                               labels = factor.levels[which.panel[2]])
>            }
>        })
>
> -Deepayan



More information about the R-help mailing list