ggplot图例:键相对于标签的位置 [英] ggplot legend: position of key relative to labels

查看:106
本文介绍了ggplot图例:键相对于标签的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ggplot制作一个图例,其图例水平位于图的上方.我的变量有多个图例(例如颜色,形状,线型).

I'm using ggplot to make a graph with the legend positioned horizontally above the plot. There are multiple legends for my variables (ie color, shape, linetype).

+ theme(legend.position = 'top', legend.direction = "horizontal", legend.box = "horizontal")

无论如何,是否有将每个图例的标题放在描述上方而不是侧面

Is there anyway to put the title of each legend above the descriptions rather than to the side

和/或

将键放在标签文本上方.

place the key above the label text.

推荐答案

是为每种美学效果添加guides(...)之类的东西吗?

Something like adding guides(...) for each aesthetic?

ggplot(diamonds, aes(depth, price, color = cut)) + 
  geom_point() +  
  theme(legend.position = 'top', 
        legend.direction = "horizontal", 
        legend.box = "horizontal") + 
  guides(color = guide_legend(title.position = "top", 
                              # hjust = 0.5 centres the title horizontally
                              title.hjust = 0.5,
                              label.position = "bottom")) 

这篇关于ggplot图例:键相对于标签的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆