Help on creating a filled contour graph

ggplot2

#1

Hi! I'm relatively new to r, or rather I simply have experience with simple data analysis(plugging in numbers and data into codes, etc). I've recently come across graphs that look like so (http://i.stack.imgur.com/hjPJs.png), and would love to learn how to do something like this. I've been reading through a bunch of blog posts and have learned that this can be done with the ggplot2 package which I have downloaded.

With that said, I am looking to generate a graph that displays temperature per depth (m) over a period of time, all of which I have the data for. For example, we have an array that reads temperature daily from a lake at certain depths (3-18m) every few minutes. I'm looking to turn this into a visual graph that can easily show the change in temperature over time.

Thank you for any help that is given in advance.


#2

<edited to make unique variables - oops!>

That should be possible. I presume a geom_area or geom_col or geom_tile layer would work, depending on the shape of the data. If T is time, depth is M, and temp is C, it might look like:

library(tidyverse)

ggplot(YOUR_DATA, aes(x = T, y = M, fill = C)) +
  geom_tile() +
  scale_y_reverse()  # Since high depth should be at the bottom, presumably.

http://ggplot2.tidyverse.org/reference/index.html
http://ggplot2.tidyverse.org/reference/position_stack.html


#3

If your data is sparse and you’re looking for interpolation, you might look here. The 2nd to last example looks similar to your situation.

http://ggplot2.tidyverse.org/reference/geom_density_2d.html