ggplot2 legend to bottom and horizontal

后端 未结 2 1487
忘了有多久
忘了有多久 2021-01-30 09:51

How can I move a ggplot2 legend to the bottom of the plot and turn it horizontally?

Sample code:

library(reshape2) # for melt
df <- m         


        
2条回答
  •  感情败类
    2021-01-30 10:33

    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. Legend at bottom

提交回复
热议问题