1

我正在寻找 1)“A”、“B”和“C”之间的更多垂直空间,“\n”不是我想要的解决方案。2)我想改变符号和文本的绘制顺序。这意味着,首先我想绘制图例的线条,然后是该文本。

 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)
            ) 
4

1 回答 1

3

从美学的角度来看,我认为这更好,但您可以通过更改关键参数的“x”和“y”参数来移动它以适应您的感受:

 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 )
            )

我不认为你可以用'auto.key'或'simpleKey'来做到这一点。)

于 2012-10-09T01:57:13.177 回答