【问题标题】:visualise difference between two geom_hex plots by subtracting data通过减去数据可视化两个 geom_hex 图之间的差异
【发布时间】:2020-10-29 19:39:48
【问题描述】:

有没有办法用新的第三个六边形图来可视化两个geom_hex 图之间的差异?

ggplot(diamonds, aes(carat, price)) +
  geom_hex(aes(fill = stat(ncount)))

set.seed(123)
diamonds2 <- diamonds %>%
  mutate(price = jitter(price, amount = 500), carat = jitter(carat, amount = 2))

ggplot(diamonds2, aes(carat, price)) +
  geom_hex(aes(fill = stat(ncount)))

我曾考虑使用 ggplot_build 提取数据,对其进行操作并重新组装绘图,但这会导致问题,即 bin 不一样,我需要以某种方式调整颜色规模。

非常感谢您对如何实现这一目标的任何想法。

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:

    一种方法是使用alphacol

    library(tidyverse)
    
    set.seed(123)
    diamonds2 <- diamonds %>%
      mutate(price = jitter(price, amount = 500), carat = jitter(carat, amount = 2))
    
    
    ggplot() +
      geom_hex(data = diamonds, aes(carat, price, col = "red", alpha = 0.3, fill = stat(ncount))) +
      geom_hex(data = diamonds2, aes(carat, price, col = "blue", alpha = 0.3, fill = stat(ncount)))
    

    reprex package (v0.3.0) 于 2020 年 10 月 29 日创建

    【讨论】:

    • 是的,我可以这样做,谢谢。但是我实际上希望创建第三个显示差异的图
    猜你喜欢
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 2016-06-24
    • 1970-01-01
    • 2021-10-16
    • 2019-10-04
    • 1970-01-01
    相关资源
    最近更新 更多