简体   繁体   English

使用ggplot2将2维数据“压缩”到热图中

[英]“squeezing” 2 dimensions of data into heatmap using ggplot2

I have a dataframe like the one below: 我有一个像下面的数据框:

obj date    colour  measurement
A   01      red     10
A   02      green   20
A   03      red     5
B   01      green   10
B   02      red     30
B   03      red     50

I know how to present df[,c("obj","date","colour")] in a heatmap format: 我知道如何以热图格式显示df [,c(“ obj”,“ date”,“ colour”)]:

chart <- ggplot(data=temp.df,aes(x=date,y=obj,fill=colour))
chart <- chart + geom_tile()

But I want to "squeeze" the "measurement" variable into the plot also, by opacity. 但是我也想通过不透明度将“测量”变量“压缩”到图中。 That is for A-03, it will be the lightest red, and for B-03, it will be the darkest red. 那是对于A-03,它将是最浅的红色,对于B-03,它将是最暗的红色。

Is it doable in R and ggplot2? 它在R和ggplot2中可行吗? Thanks. 谢谢。

alpha is what you are looking for. alpha是您要寻找的。 Still working on getting a reasonable legend. 仍在努力寻找合理的传说。

 ggplot(df, aes(x=obj,y=date,fill = colour, alpha = measurement)) + 
     geom_tile() + 
     scale_fill_identity() + scale_alpha(guide = 'none')+
     theme_bw() + opts(panel.grid.major = theme_blank()) 

在此处输入图片说明

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

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