简体   繁体   English

R中随时间变化的热图密度

[英]Heat Map Density Over Time in R

A sample dataset is provided below. 下面提供了样本数据集。

I'm not sure if there is a name for the graph I'm thinking of. 我不确定我在想图的名字。 I have a value recorded daily, and rather than create a simple line graph, I'd like to display it as if looking at a body of water from above, where shallow depths are light and deeper depths are colored darker. 我每天都会记录一个值,而不是创建一个简单的折线图,而是要像从上方看水一样显示该值,浅处浅而浅处深。

I'm just looking to create a simple rectangle, where Date is on the X axis, the Y axis is just a uniform value, and the Color of the line at the date is defined by the Value recorded, without any spacing between the lines at each date. 我只是想创建一个简单的矩形,其中Date在X轴上,Y轴只是一个统一的值,并且该日期的行的颜色由记录的值定义,行之间没有任何间隔在每个日期。

I'm hoping it would look something like this color scale line, with differing shades at differing depths, and with user control over the color at maximal depth. 我希望它看起来像这样的色标线,在不同深度具有不同的阴影,并且用户可以在最大深度控制颜色。

色阶

I'm relatively new to visualizations in R, and my main goal is simply to experiment with different ways to represent some simple data. 我对R中的可视化还比较陌生,我的主要目标只是简单地尝试用不同的方法来表示一些简单的数据。 I'd appreciate any suggestions regarding what I could do to learn how to create not just a graph like this, but perhaps other non-traditional graphs in the future. 对于我可以做些什么来学习如何不仅创建像这样的图,而且将来可能还会创建其他非传统图,我将不胜感激。

D <- structure(list(Date = structure(c(16709, 16710, 16711, 16712, 
16713, 16714, 16715, 16716, 16717, 16718, 16719, 16720, 16721, 
16722, 16723, 16724, 16725, 16726, 16727, 16728, 16729, 16730, 
16731, 16732, 16733, 16734, 16735, 16736, 16737, 16738), class = "Date"), 
Length = c(288, 426, 315, 844, 587, 224, 859, 1052, 892, 
483, 497, 927, 2697, 1647, 2494, 1525, 0, 0, 1263, 0, 753, 
671, 673, 792, 1615, 739, 1268, 367, 0, 120)), class = c("tbl_df", 
"tbl", "data.frame"), row.names = c(NA, -30L), .Names = c("Date", "Value"))

Edit: 编辑:

I'm currently working with geom_raster() in ggplot2 . 我目前正与geom_raster()ggplot2 It's not as pretty as I thought it would be, but I'll take this as a starting point. 它没有我想的那么漂亮,但是我将以此为起点。

library(dplyr)

ggplot(D %>% mutate(y = 1),
   aes(x = Date, y = y, fill = Value)) +
  geom_raster() +
  scale_fill_gradientn(colors = c("white", "black"))

A not so pretty result. 一个不太漂亮的结果。 I am sure you can adjust some settings in the image function to make it nicer. 我确定您可以调整图像功能中的某些设置以使其更美观。

library(dplyr)
I <- D %>% arrange(Date)
M <- as.matrix(I$Value, nrow=1)
image(M)

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

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