1

if I have an integer vector (or if I put it into a matrix), is there anyway to plot a heatmap using ggplot or other packages that can give me each point as a circle instead of a tile?

> 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

Such that it looks something like this (arranged in a x times y matrix): enter image description here

Jeff238
  • 396
  • 2
  • 15
  • Can you please provide your `counts` object as code, i.e. by providing the output of `dput(counts)` in the body of your question? – Jon Spring Oct 16 '21 at 17:17

1 Answers1

5

If you want the circles to touch regardless of zoom, ggforce::geom_circles might help:

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()

enter image description here

Jon Spring
  • 55,165
  • 4
  • 35
  • 53