简体   繁体   English

r 中具有分类计数和时间的热图数据可视化

[英]heatmap data visualization with categorical count and time in r

I am trying to create a simple heatmap that has a list of non-redundant category character (heat$cat) on the y-axis and date/time as the x-axis.我正在尝试创建一个简单的热图,它在 y 轴上有一个非冗余类别字符 (heat$cat) 的列表,在 x 轴上有一个日期/时间。 Two customization on the heat map 1) The headmap gradient reflect the frequency count of categories (heat$cat),eg 1-2=blue, 3 or above =dark;热度map上的两个自定义 1) headmap梯度反映类别的频率计数(heat$cat),例如1-2=蓝色,3或以上=dark; 2)The total frequency count of (heat$cat) should display on the right hand side of the heatmap. 2) (heat$cat) 的总频率计数应显示在热图的右侧。

Here is the dataset, thanks very much for your input!这是数据集,非常感谢您的输入!

cat<-c("A","A","A","C","D","E","E","E","F","F")
date<-c("05-05-2020","05-05-2020","05-05-2020","04-05-2020","05-05-2020","04-05-2020","03-05-2020","04-05-2020","04-05-2020","04-05-2020" )
date<-as.Date(format(date, format="%d-%m-%Y"))
heat<-cbind(cat,date)

The date format doesn't seem correct.. Anyway, you make it a factor, then use dplyr to group and fill in the zeros.日期格式似乎不正确。无论如何,您将其作为一个因素,然后使用 dplyr 进行分组并填写零。 Pipe it into ggplot and use geom_tile() for heatmap: Pipe 进入 ggplot 并使用 geom_tile() 作为热图:

library(dplyr)
library(ggplot2)

date <- as.Date(date,"%d-%m-%Y")
data.frame(cat=cat,date=factor(date)) %>% 
count(cat,date,.drop=FALSE) %>% 
ggplot(aes(x=date,y=cat,fill=n)) + geom_tile()

在此处输入图像描述

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

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