Klaus
Klaus

Reputation: 2056

Look and feel of legend in lattice plots

I'm looking for 1) more vertical space between "A", "B" and "C", "\n" is not a solution Iam lokking for. 2) I want to change the plotting order of symbols and text. That means, first I want to plot the lines of the legend and after that text.

 attach(mtcars)
 gear.f<-factor(gear,levels=c(3,4,5),
 labels=c("3gears","4gears","5gears"))
 cyl.f <-factor(cyl,levels=c(4,6,8),
 labels=c("4cyl","6cyl","8cyl"))

 densityplot(~mpg|cyl.f,
      main="Density Plot by Number of Cylinders",
      xlab="Miles per Gallon"
     ,par.settings = list(superpose.line = list(col=c(1,2,3)))
     ,auto.key=list(corner = c(.98, .02),text = c("A", "B", "C")
                   ,lines=T,points=F)
            ) 

Upvotes: 1

Views: 2487

Answers (1)

IRTFM
IRTFM

Reputation: 263481

I think this is better from an aesthetic viewpoint but you can move it around to suit you sensibilities by altering the 'x' and 'y' arguments to the key parameter:

 densityplot(~mpg|cyl.f,
      main="Density Plot by Number of Cylinders",
      xlab="Miles per Gallon"
     ,par.settings = list(superpose.line = list(col=c(1,2,3)))
     ,key = list(lines = list(col=c("black", "red", "green")),
                  text = list(c("A", "B", "C")), x=0.8, y=0.8, corner.x=0,corner.y=0 )
            )

I do not think you can do it with 'auto.key' or 'simpleKey'.)

Upvotes: 3

Related Questions