简体   繁体   中英

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.

在此处输入图片说明

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.

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.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM