Reputation: 816
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.
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. 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
. 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"))
Upvotes: 0
Views: 339
Reputation: 6020
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)
Upvotes: 1