Hugo Sereno Ferreira
Hugo Sereno Ferreira

Reputation: 8621

Heat Table in R

I'm looking for a way to duplicate the kind of Heat Table shown below with R (and possibly ggplot2). Specific time axis are irrelevant; any rectangular table should do.

enter image description here

I've tried to search for Heat map and Heat table in Google, but couldn't find any R package that did the trick.

Thoughts?

Upvotes: 2

Views: 872

Answers (1)

Gregor Thomas
Gregor Thomas

Reputation: 145755

require(ggplot2)
df <- data.frame(vaxis = rep(c(letters[1:5], "top"), each = 4),
                 haxis = rep(c(letters[6:8], "right"), times = 6),
                 value = rpois(24, lambda = 10))
df$color <- factor(ifelse(df$vaxis == "top" | df$haxis == "right", 1, 0))
ggplot(df, aes(x = haxis, y = vaxis, size = value, color = color)) + geom_point()

Just get your data in a similar format. You could write a function to make the "top" and "right" values normalized marginal sums. Of course lots of tweaks are possible in naming, legends, theme, etc.

plot

Upvotes: 8

Related Questions