AW27
AW27

Reputation: 505

Change Scale of Heatmap to Show More Colours

I currently have something similar to the below data, with a potentially finer grid. I was wondering if it was possible to make the grid on the ggplot heatmap finer? Meaning providing more colours for different values of z. As of now, my current plot is mostly 1 colour as they are all between 1e-2 and 1e-5, but I have one value at 1e-13 and cannot seem to see it at all.

x <- seq(3, 5, by = 1)
y <- seq(5, 101, by = 2)
z <- seq(3, 10^-13, length = 146)
### Combinations
combinations <- expand_grid(x, y) %>%
  subset(y > x) %>%
  cbind(z) %>%
  as.matrix()

combinations %>%
  ggplot(aes(x = x, y = y)) +
  geom_tile(aes(fill = z))

Thanks in advance.

Upvotes: 0

Views: 171

Answers (1)

Marek Fiołka
Marek Fiołka

Reputation: 4949

Or was that about it?

x <- seq(3, 5, by = 1)
y <- seq(5, 101, by = 2)
z <- seq(3, 10^-13, length = 146)

combinations <- expand_grid(x, y) %>%
  subset(y > x) %>%
  cbind(z)

combinations %>%
  ggplot(aes(x, y, z=z)) +
  geom_contour_filled()+
  geom_point(data = combinations %>% filter(z<1e-6),
             size=10, color = "red")

Do it this way. It has to work !!

library(tidyverse)
library(ggplot2)

x <- seq(3, 5, by = 1)
y <- seq(5, 101, by = 2)
z <- seq(3, 10^-13, length = 146)

combinations <- expand_grid(x, y) %>%
  subset(y > x) %>%
  cbind(z)

combinations %>%
  ggplot(aes(x, y, z=z)) +
  geom_contour_filled()+
  geom_point(data = combinations %>% dplyr::filter(z<1e-6),
             size=10, color = "red")

Upvotes: 2

Related Questions