简体   繁体   English

为带有x和y轴标签的第三个变量创建图?

[英]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. 我正在尝试绘制与此图形类似的图形 ,请参阅第32页,图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. 您可以修改scale_fill...函数,以根据var(连续或离散)或某些规则集实现所需的任何布局。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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