Я искал аналогичный ответ. Но обнаружил, что функция opts
больше не является частью пакета ggplot2. После поиска еще немного времени, я обнаружил, что можно использовать theme
для того, чтобы делать то же самое, что и опционы. Поэтому отредактируйте этот поток, чтобы минимизировать время.
Ниже приведен код, написанный nzcoops.
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)) + labs(title = "Legend is top left") +
theme(legend.justification = c(0, 1), legend.position = c(0, 1))
b <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + labs(title = "Legend is bottom right") +
theme(legend.justification = c(1, 0), legend.position = c(1, 0))
c <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + labs(title = "Legend is bottom left") +
theme(legend.justification = c(0, 0), legend.position = c(0, 0))
d <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + labs(title = "Legend is top right") +
theme(legend.justification = c(1, 1), legend.position = c(1, 1))
grid.arrange(a,b,c,d)
Этот код даст точно такой же график.