r - ggplot2图例到底部和水平

标签 r ggplot2

如何将 ggplot2 图例移动到绘图底部并将其水平旋转?

示例代码:

library(reshape2) # for melt
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p1 + scale_fill_continuous(guide = guide_legend())

期望的(近似)结果: enter image description here

最佳答案

如果您想移动图例的位置,请使用以下代码:

library(reshape2) # for melt
df <- melt(outer(1:4, 1:4), varnames = c("X1", "X2"))
p1 <- ggplot(df, aes(X1, X2)) + geom_tile(aes(fill = value))
p1 + scale_fill_continuous(guide = guide_legend()) +
    theme(legend.position="bottom")

这应该会给你想要的结果。 Legend at bottom

关于r - ggplot2图例到底部和水平,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10032513/

相关文章:

R 在一张图中绘制来自不同数据帧的箱线图

r - R中的ImageMagick

r - 获取R中表函数中唯一行的总和

R多列之间的多热编码

r - R 中的堆积条形图 (ggplot2),其中 y 轴和条形作为计数百分比

r - 如何在 R Shiny 中增加 ggplot2 图的绝对大小?

r - 非分面图中的分面式标题

r - 在 R 中使用 geom_smooth() 在 ggplot2 图例中混合填充颜色

r - 计算 Quanteda 语料库中每个文档中的某些字母

r - R中对角线之间的矩阵元素之和有效