图例标题位置使用错落有致?
Legend title position using patchwork?
我已经使用拼凑法布置了 2 个图表,并在底部有一个描述它们的图例。图例有一个水平方向,我试图将标题移到顶部,而不是左侧的默认值。当我使用
guides(
fill = guide_legend(title.position = "top")
)
(连续)图例转换为离散图例。有没有简单的方法可以防止这种情况发生?
在 ggplot
中,guide_legend
表示您需要独立的图例键。我认为您正在寻找 guide_colorbar
.
为了演示,让我们重现您的问题。一、原剧情:
library(ggplot2)
set.seed(69)
df <- data.frame(x = 1:10, y = sample(10), z = 1:10)
p <- ggplot(df, aes(x, y, fill = z)) +
geom_col() +
theme(legend.position = "bottom")
p
现在,您正在使用的导致问题的代码:
p + guides(fill = guide_legend(title.position = "top"))
以及解析它的代码:
p + guides(fill = guide_colorbar(title.position = "top"))
由 reprex package (v0.3.0)
于 2020-08-07 创建
我已经使用拼凑法布置了 2 个图表,并在底部有一个描述它们的图例。图例有一个水平方向,我试图将标题移到顶部,而不是左侧的默认值。当我使用
guides(
fill = guide_legend(title.position = "top")
)
(连续)图例转换为离散图例。有没有简单的方法可以防止这种情况发生?
在 ggplot
中,guide_legend
表示您需要独立的图例键。我认为您正在寻找 guide_colorbar
.
为了演示,让我们重现您的问题。一、原剧情:
library(ggplot2)
set.seed(69)
df <- data.frame(x = 1:10, y = sample(10), z = 1:10)
p <- ggplot(df, aes(x, y, fill = z)) +
geom_col() +
theme(legend.position = "bottom")
p
现在,您正在使用的导致问题的代码:
p + guides(fill = guide_legend(title.position = "top"))
以及解析它的代码:
p + guides(fill = guide_colorbar(title.position = "top"))
由 reprex package (v0.3.0)
于 2020-08-07 创建