Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legend glyphs for geom_pointrange do not follow their plotted direction #4732

Closed
andrewheiss opened this issue Feb 10, 2022 · 4 comments · Fixed by #4757
Closed

Legend glyphs for geom_pointrange do not follow their plotted direction #4732

andrewheiss opened this issue Feb 10, 2022 · 4 comments · Fixed by #4757
Labels
feature a feature request or enhancement guides 📏

Comments

@andrewheiss
Copy link

andrewheiss commented Feb 10, 2022

(This is super similar to this past issue #1389, but the addition of bidirectional geoms in v3.3.0 have changed the circumstances of that original issue)


Since ggplot2 3.3.0, geoms like geom_boxplot() and geom_pointrange() work with either the x or the y aesthetic, thus eliminating the need for packages like {ggstance} for horizontal point ranges:

library(ggplot2)

df <- data.frame(x = 1:3, y = 1:3)

ggplot(df, aes(x = x, y = y, color = factor(x))) +
  geom_pointrange(aes(xmin = x - 1, xmax = x + 1))

Currently, however, the legend keys for point ranges show vertical lines regardless of the direction of the actual point range. There are ways to adjust the legend keys by either modifying some of the underlying grid grobs, or by adding an empty stat_summary() layer in combination with geom_point() and geom_line() (example), but these are fairly hacky.

In a previous issue #1389, the official recommendation from Hadley was to use ggstance, but now that geom_pointrange() can go an any direction now since v3.3.0, it would be neat if the legend glyphs matched the direction of the geoms for things like point ranges and box plots. I have no idea how feasible or difficult that would be though.

Thanks!

@mjskay
Copy link
Contributor

mjskay commented Feb 10, 2022

(looking up how I solved this in ggdist) It should be possible to check params$orientation inside draw_key_pointrange() and then use either draw_key_path() or draw_key_vpath() on this line depending on the current orientation:

draw_key_vpath(data, params, size),

@smouksassi
Copy link

we also need this for horizontal boxplots legend
also not sure how to communicate the fatten setting to geom pointrange legend

@hadley
Copy link
Member

hadley commented Mar 14, 2022

@mjskay any interests in doing a PR for this?

@hadley hadley added feature a feature request or enhancement guides 📏 labels Mar 14, 2022
@mjskay
Copy link
Contributor

mjskay commented Mar 15, 2022

Sure, I could take a look.

mjskay added a commit to mjskay/ggplot2 that referenced this issue Mar 15, 2022
mjskay added a commit to mjskay/ggplot2 that referenced this issue Mar 15, 2022
hadley pushed a commit that referenced this issue Mar 23, 2022
yufree pushed a commit to cosname/cosx.org that referenced this issue May 22, 2022
* 专题地图与 R 语言及其应用

* use optipng -o5

* 用 https://tinypng.com 继续优化 MB 级的图片

* tweak texts

* use xfun::tinify to optimize png files

* polish

* tweak text

* 调整文本

* 添加文章目录

* 继续抛光

* tweak

* 如此这般调整癌症死亡率

* add blogdown

* 北卡收入分布全宽展示

* 应用全宽方案

* 小调整

* 补充人口年龄结构图的代码

* 让全宽图的 caption 居中

* 删掉一些感情色彩强烈的经验总结

* 继续清理有情绪的部分

* cleanup

* 继续清理和很小的代码修正

* reorg

* 优化 CI Rank 图,用 `geom_pointrange` 替代 `geom_segment`,但 ggplot2 似乎有不能排序的 BUG

* 尝试安装开发版 ggplot2 解决,但是只解决了图例方向问题,详见 tidyverse/ggplot2#4732

* 补充优化 CI 图片

* 要使用分组排序 reorder 其实不是 ggplot2 的 BUG

* tweak text

* 补充 leaflet 绘图代码

* tweak code

* 既然有很多至少也添加两个技术方案

* 7 其它表达细节

* 全文涉及美国的「城镇」都改为「郡」,「专题地图」改为「地区分布图」,这样通俗合理一些

* 默认图层和符号图层对比

* 家庭收入中位数 -- 家庭月收入

* 添加 lattice 绘图步骤

* 再加一点 7 种方案的技术总结

* reorg code

* 在 Ubuntu 下竟可以用 tidycensus 直接下载数据,故而重新组织代码和数据,大瘦身 🚀

* 去掉全宽图形

* 修复北卡社区级家庭月收入的空间分布图,之前手动从网站下载的地图数据有些微的问题,即 ACS 调查的年份 2019 和地图数据的年份 2020 不一致

* 美国各个郡的家庭月收入

* 添加各州、郡家庭月收入数据

* 忽略缓存目录

* 添加宽格式和长格式的展示

* 万里长征快走完了

* 更新社区级二元地区分布图

* 莫兰指数刻画空间相关性,获取具体的城镇,以便后续解读数据

* 重画家庭月收入图,添加计算莫兰指数的 R 包说明

* 莫兰指数地图

* Polish

* 最后提及交互式图形,引一下两篇个人博客,以示了解

* 在二元地图中,缺失数据的社区以白色块填充

* 交待一下空间上有部分社区的数据缺失的原因

* * 是家庭年收入,统一修改,交待数据指标的实际含义

* 交待用到的地图数据

* cleanup

* 白人占比也在空间集聚

* 根据审稿人意见修改文本,添加论坛 ID

* tweak text

* update date and cleanup

* 代码中家庭月收入 --> 家庭年收入

* tweak

* tweak text

* minor update

* 更新日期 2022-05-13

* 继续清理未使用到的代码、超宽代码等

* 一些文本编辑和格式化
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement guides 📏
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants