Krivers
Krivers

Reputation: 2056

Plot overlapping rectangles

I have a dataset that looks like this:

x, y, width, height
10,20,30,30
11,25,35,30

Is there any way to create in R a simple heatmap of the rectangular area?
Just like following image (or something similar):

enter image description here

Upvotes: 1

Views: 456

Answers (1)

pogibas
pogibas

Reputation: 28379

You can use ggplot2 package and geom_rect layer (specify cornes with xmin, xmax, ymin, ymax).

library(ggplot2)
ggplot(data, aes(xmin = x, xmax = x + width,
                 ymin = y, ymax = y + height)) +
    geom_rect(color = NA, fill = "grey", alpha = 0.4) +
    theme_void() +
    theme(plot.background = element_rect(fill = "black"))

enter image description here

Upvotes: 2

Related Questions