ScottF
ScottF

Reputation: 11

Create a plot for a third variable with x and y axis labels?

I'm trying to plot something similar to this graphic, see p.32, figure 14.

enter image description here

Seems quite simple, but I have not been able to find a specific example through online searching. If anyone can help, I would really appreciate it.

Upvotes: 1

Views: 113

Answers (1)

Troy
Troy

Reputation: 8691

How about this:

library(ggplot2)

df<-expand.grid(x=LETTERS,y=1:20)
df$var<-runif(nrow(df))    

ggplot(df[sample(1:nrow(df),200),]) + theme_bw() + # subset of df to include blanks
  geom_tile(aes(x=x,y=y,fill=var)) + #geom_tile
  scale_fill_gradient2(low="green",mid="yellow",high="red",midpoint=0.5) + # add fill gradient
  scale_y_discrete(breaks=1:20,labels=1:20) +
  coord_fixed(ylim=c(0.5,20.5))

you can tinker with the scale_fill... functions to acheive whatever layout you want, either based on var (continuous or discrete), or some set of rules.

enter image description here

Upvotes: 2

Related Questions