r - 左对齐多行ggplot2图例
问题描述
我有一个具有不同宽度的两部分图例:
library(dplyr)
library(ggplot2)
mtcars %>%
mutate(qsec = factor(qsec)) %>%
ggplot(aes(mpg, cyl, fill = qsec, linetype = 'short legend')) +
geom_col() +
guides(fill = guide_legend(title.position = 'top', label.position = 'bottom'),
linetype = guide_legend(title.position = 'top',
label.position = 'bottom')) +
theme(legend.position = 'bottom',
legend.box = 'vertical')
是否可以左对齐linetype
图例以匹配填充图例?
由reprex 包(v0.3.0)于 2021-01-21 创建
解决方案
也许legend.box.just = "left"
参数是您正在寻找的?
mtcars %>%
mutate(qsec = factor(qsec)) %>%
ggplot(aes(mpg, cyl, fill = qsec, linetype = 'short legend')) +
geom_col() +
guides(fill = guide_legend(title.position = 'top', label.position = 'bottom'),
linetype = guide_legend(title.position = 'top',
label.position = 'bottom')) +
theme(legend.position = 'bottom',
legend.box.just = "left",
legend.box = "vertical" )
推荐阅读
- java - OkHttp 异步调用返回 JsonArray Null
- android - 如何使用 WorkManager 和 OneTimeWorkRequest 在 Android 中的特定时间接收每日通知?
- docker - 启用了 selinux 的 Docker - 不允许在 /usr 中重新标记内容
- jspdf - 如何使用 jsPDF 和 jSPDF autoTable 在特定单元格中绘制圆角矩形?
- c++ - 即使 QFilterKey 匹配,QRenderPassFilter 也会隐藏平面网格
- javascript - 查看 Apple Pay 价格
- react-native - 反应导航不响应单击按钮
- java - 如何为文件处理问题编写代码
- .net - .net cad:从另一个图纸导入尺寸样式
- java - 使用 Spring Data Jpa 时如何使用大型脚本查询数据?