【问题标题】:Heatmap with circles instead of tiles in ggplotggplot中带有圆圈而不是瓷砖的热图
【发布时间】:2021-12-04 10:10:42
【问题描述】:

如果我有一个整数向量(或者如果我将它放入矩阵中),是否可以使用 ggplot 或其他可以将每个点作为圆而不是平铺的包来绘制热图?

> counts
  [1] 1949 1690 1935 2480 1441 1141 2079 1587  517 1028  535 2180 1692 3916 1784
 [16] 3028 1911 1329 1759 1478 1080 2835 2187 3230 2932 3527 1538 1489 1493 1170
 [31] 3311 4982 4842 4899 1339 3594 2562 1821 1077 1072 4312 3395 3522 1037 3270
 [46] 4813 1686 1955 3290 1288 2592 3717  213 2840 3938 3882 1807 1582 2519 2600
 [61] 4093 2318 3028 3074 1833 3453 2539 2665 2491 2696 2819 1177 1707 1832 3223
 [76] 2366 3742 2648 1594 2112 2239 2840  414 1094 2621 3116 1939 2847 1781 1054
 [91] 1098 1977 1061 2441 2367  723 1126 2550  586  515

它看起来像这样(排列在 x 乘 y 矩阵中):

【问题讨论】:

  • 您能否将您的counts 对象作为代码提供,即在您的问题正文中提供dput(counts) 的输出?

标签: r ggplot2 heatmap


【解决方案1】:

如果您希望无论缩放如何都可以触摸圆圈,ggforce::geom_circles 可能会有所帮助:

z <- runif(100, 0, 5000)  
  
library(dplyr); library(ggplot2)
data.frame(z = z) %>%
  mutate(row = (row_number() - 1) %/% 10 + 1,
         col = (row_number() - 1) %% 10 + 1) %>% 
  ggplot() +
  ggforce::geom_circle(aes(x0 = col, y0 = row, fill = z, r = 0.5)) +
  scale_y_reverse() +
  scale_fill_gradient(low = "yellow", high = "red", breaks = 1000*(0:6)) +
  guides(fill = guide_colorsteps(barwidth = 0.3, barheight = 17)) +
  coord_equal(clip = "off") +
  theme_void()

【讨论】:

  • 真的很酷!我们可以在实践中应用这种视觉效果吗?
猜你喜欢
  • 1970-01-01
  • 2012-12-10
  • 1970-01-01
  • 1970-01-01
  • 2013-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-03
相关资源
最近更新 更多