【问题标题】:move ggplot2 legend to top right corner?将ggplot2图例移动到右上角?
【发布时间】:2015-08-20 17:44:09
【问题描述】:

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

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

【问题讨论】:

标签: r ggplot2


【解决方案1】:

试试:

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

【讨论】:

    猜你喜欢
    • 2018-08-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-04
    • 1970-01-01
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    相关资源
    最近更新 更多