0

I use heat maps in ggplot2 to visualize how different groups engage with texts. The more frequently a group cites a given text, the more brightly it shows up in the heat map, which is arranged such that groups are on the y-axis and book titles are aligned on the x-axis.

The same data I use to generate heat maps I also use to calculate the Euclidean distance between groups' citation patterns. My practice is usually to report these distances in tables. However, I would like to find a way to include some of the Euclidean distances in my presentation of heat maps. A handy way to do that would be to space the groups along the y-axis by their distance from a focal group's data. I have not, however, found any way to force variable spacing between categories on ggplot2. Surely there's a call to make this possible, but I've run out of places to look.

  • 1
    Can you please add a [minimum reproducable example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) of the problem which includes sample data. – Mist Dec 26 '15 at 21:47

1 Answers1

0

Does this help at all?

library(ggplot2)
df <- data.frame(books = c("Book1", "Book1", "Book1"),
                 groups = c("Group1", "Group2", "Group3"),
                 citations = c(1,2,3),
                 distance = c(10,20,50))

ggplot(data = df) +
  geom_rect(aes(xmin = distance,
                xmax = distance + 1,
                ymin = rep(1,3),
                ymax = rep(2,3),
                alpha = citations/max(citations))) +
  scale_x_continuous(breaks = df$distance,
                     labels = levels(df$groups)) +
  scale_y_continuous(breaks = 1:length(levels(df$books)),
                     labels = levels(df$books))
Mist
  • 1,888
  • 1
  • 14
  • 21