将ggplot2传奇移到右上角?

时间:2015-08-20 17:44:10

标签: r ggplot2

我想让我的情节中的传奇水平并将其移动到右上角。那可能吗?

DF3 <- data.frame(
  x = rnorm(100, mean = 0, sd = 1),
  y = rnorm(n = 100, mean = 1, sd = 1),
  shape = sample(
    x = c('circle', 'square'), size = 100, replace = T, prob = c(.5,.5)
  ),
  Precision = runif(n = 100, min = 0.1, max = 1)
)

library(ggplot2)

DF3 %>%
  ggplot(aes(
    x = x, y = y, color = Precision, size = 2, shape = shape
  )) +
  geom_point(show_guide = TRUE) + 
  theme_bw()+ 
  scale_colour_gradient(low = "#f7fbff", high = "#08306b") + guides(shape = "none", size="none")

1 个答案:

答案 0 :(得分:3)

尝试:

+ theme(legend.position=c(1,1),
        legend.direction="horizontal",
        legend.justification=c(1, 0), 
        legend.key.width=unit(1, "lines"), 
        legend.key.height=unit(1, "lines"), 
        plot.margin = unit(c(5, 1, 0.5, 0.5), "lines"))

enter image description here