更新:opts
已被弃用。请使用theme
代替in this answer.
只是为了扩大kohske的答案,所以对于下一个人来说,它会更全面一些。
mtcars$cyl <- factor(mtcars$cyl, labels=c("four","six","eight"))
library(gridExtra)
a <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) +
opts(legend.justification = c(0, 1), legend.position = c(0, 1), title="Legend is top left")
b <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) +
opts(legend.justification = c(1, 0), legend.position = c(1, 0), title="Legend is bottom right")
c <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) +
opts(legend.justification = c(0, 0), legend.position = c(0, 0), title="Legend is bottom left")
d <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) +
opts(legend.justification = c(1, 1), legend.position = c(1, 1), title="Legend is top right")
grid.arrange(a,b,c,d)

你是什么意思的“阴谋地区”?该区域由灰色填充? – kohske
@kohske是的,OP基本上希望能够确定'legend.position'的正确坐标,以将图例放置在“数据区域”或灰色区域的一角。正如我在聊天中提到的那样,我怀疑像你这样的人将不得不使用网格解决方案。 – joran
@joran然后,这是默认行为,所有你需要的是设置正确的理由。 – kohske