且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ggplot2图例到底部和水平

更新时间:2023-11-26 12:21:52

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

If you want to move the position of the legend please use the following code:

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

这应该给您想要的结果.

This should give you the desired result.