contour plot (times series of water temperature data) using ggplot2

3,689 views
Skip to first unread message

Al Kirschbaum

unread,
Jan 27, 2014, 5:51:20 PM1/27/14
to ggp...@googlegroups.com
Hello-

I have hourly readings of temperature at 0, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 meters beneath the surface of the water for an entire year. I would like to create a graph like this...
Depth on y axis, time on x axis and the water temperature used for z axis.

Unfortunately, due the large size of the dataset (100k observations for a year), I cannot attach the dataset, or replicate it. I have included a snippet to at least show the general outline of the data.

data <- structure(list(date_time = structure(c(1339016400, 1339020000,
                                       1339023600, 1339027200, 1339030800, 1339034400), class = c("POSIXct",
                                                                                                  "POSIXt"), tzone = ""), temperature = c(21.103, 21.199, 20.96,
                                                                                                                                          20.96, 21.103, 20.412), depth = c(0, 0, 0, 0, 0, 0)), .Names = c("date_time",
                                                                                                                                                                                                           "temperature", "depth"), row.names = c("48730", "48731", "48732",
                                                                                                                                                                                                                                                  "48733", "48734", "48735"), class = "data.frame")


You just have to imagine another 100k records!

When I use ggplot2 and the stat_contour function, I produce the following graph:

v <- ggplot(data,aes(date_time,depth,z=temperature))
v <- v + stat_contour(geom="polygon")
v <- v + scale_fill_gradientn(colours=rev(rainbow(10)))
v <- v + geom_tile(aes(fill=temperature))
v <- v + scale_y_reverse()
v





This produces a very choppy graph with no data between the depths. Of course, part of the difference between the two is that the first graph uses modeled data to fill in the gaps between depths. I believe it also models more time steps, to make a smoother graph. I tried modeling the data using the loess function which helps smooth the data, unfortunately it creates an incredibly large dataset, bumping into memory limits on my machine. Not to mention, it takes minutes to render millions of values.

Maybe I'm using the wrong tool within R to produce this type of plot. I enjoy using ggplot and would like to continue to do so. I figured this group would have a solution.

Thanks for any help or suggestions.

-al

Stuart Luppescu

unread,
Jan 27, 2014, 6:28:17 PM1/27/14
to ggp...@googlegroups.com
On Mon, 2014-01-27 at 14:51 -0800, Al Kirschbaum wrote:
> When I use ggplot2 and the stat_contour function, I produce the
> following graph:
>
> v <- ggplot(data,aes(date_time,depth,z=temperature))
> v <- v + stat_contour(geom="polygon")
> v <- v + scale_fill_gradientn(colours=rev(rainbow(10)))
> v <- v + geom_tile(aes(fill=temperature))
> v <- v + scale_y_reverse()
> v

Wow. I have no idea how to fix this, but you should definitely submit
the graph to this site:

http://accidental-art.tumblr.com/

--
Stuart Luppescu -=-=- slu <AT> ccsr <DOT> uchicago <DOT> edu
CCSR at U of C ,.;-*^*-;., ccsr.uchicago.edu
(^_^)/ 才文と智奈美の父
[Crash programs] fail because they are based on the theory that,
with nine women pregnant, you can get a baby a month.
-- Wernher von Braun

Ben Bond-Lamberty

unread,
Jan 27, 2014, 8:49:08 PM1/27/14
to ggplot2
Perhaps check out geom_raster, in particular its 'interpolate=TRUE' option?

Note that I, for one at least, can't see whatever figure you attached; and (as always) providing a sample data set (e.g. one day's worth of data) will help people help you.

Regards,
Ben



--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2
 
---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Al Kirschbaum

unread,
Jan 28, 2014, 4:09:57 PM1/28/14
to ggp...@googlegroups.com
Thanks for the replies and apologies for the graphs not showing up. Attached are the two graphs, one is called 'goal', which is what I'm trying to replicate. The other is called ggplot_graph, and is currently what I'm able to produce. I've also attached a csv containing a years' worth of data.

I just tried using the geom_raster, interpolate=T and it gives the following error:

r <- ggplot(yr_2012,aes(date_time,depth,z=temperature))
r <- r + stat_contour(geom="raster", interpolate=TRUE)
r <- r + scale_fill_gradientn(colours=rev(rainbow(10)))
r <- r + geom_tile(aes(fill=temperature))
r <- r + scale_y_reverse()
r

Error in matrix(NA_character_, nrow = nrow, ncol = ncol) : 
  invalid 'nrow' value (too large or NA)
In addition: Warning message:
In get(x, envir = this, inherits = inh)(this, ...) :
  NAs introduced by coercion


The code I'm using to create the attached 'ggplot_graph' is as follows:

v <- ggplot(yr_2012,aes(date_time,depth,z=temperature))

v <- v + stat_contour(geom="polygon")
v <- v + scale_fill_gradientn(colours=rev(rainbow(10)))
v <- v + geom_tile(aes(fill=temperature))
v <- v + scale_y_reverse()
v

I could also supply the code to reproduce one days' worth of values, however it would still be nearly 300 data points (12 depth locations * 24 hrs).

Thanks again
-al
yr_2012.csv
goal.PNG
ggplot_graph.png

Dennis Murphy

unread,
Jan 28, 2014, 6:19:43 PM1/28/14
to Al Kirschbaum, ggplot2
Hi:

That density plot you attached is really nice, but unfortunately your data don't support that degree of granularity in depth (it does in time, though). Here's a way to get started using geom_tile() and converting your depths to factor since there are only 12 unique depths. Unfortunately, this places a gap of 1 between 0 and 1.5 and again between 1.5 and 2. One option is to only use the integer part of depth (easy) or insist upon the actual depths listed (harder to deal with). I went the easy route. Here's some code to come up with an initial plot:

yr_2012 <- read.csv("yr_2012.csv", header = TRUE)

# Convert date-times to POSIXct
tms <- strptime(as.character(yr_2012$date_time), format = "%m/%d/%Y %H:%M")
yr_2012$date_time <- as.POSIXct(tms)

# Create factor for depth
yr_2012$Depth <- factor(yr_2012$depth, levels = c(11:2, 1.5, 0))

library(plyr)
library(ggplot2)
# sort by date_time and Depth
yr_2012 <- arrange(yr_2012, date_time, Depth)


ggplot(yr_2012, aes(x = date_time, y = Depth)) +
   geom_tile(aes(fill = temperature), position = "identity") +
   scale_fill_gradient(low = "blue", high = "yellow")

Some comments:

1. You can always play around with the fill gradient colors - see scale_fill_gradient2() or scale_fill_gradientn() for alternatives.
2. You can change the y-heights of the tiles, but it won't be trivial to do given the size of your data frame. There is an example or two in the on-line help page for geom_tile(), http://docs.ggplot2.org/current/geom_tile.html (about 3/4 of the way down, just before the pretty colored tile plots at the bottom) to give you a hint of what is required, but your data set is much bigger and will require a programmatic approach to define the differences in depth required for geom_tile().
3. You can also play around with the tick marks and other features of the colorbar if you wish:


Dennis

Dan Crocker

unread,
Apr 10, 2017, 9:21:29 AM4/10/17
to ggplot2
Al or others, 

I am trying to make the exact same plot with similar data (see below). I have run into all of the same errors and shortcomings and hoping someone could share a working solution (I did not see one here). I have tried using just the date for the x value and date-time - that is the only reason that both are in the dataframe. 

> str(profdata1)
'data.frame': 791 obs. of  4 variables:
 $ Date    : Date, format: "2015-05-07" "2015-05-07" "2015-05-07" "2015-05-07" ...
 $ Depth   : num  0.6 1 2 4 6 8 10 12 14 16 ...
 $ Temp    : num  11.6 11.3 11 10.9 10.8 ...
 $ DateTime: POSIXct, format: "2015-05-07 09:02:03" "2015-05-07 09:02:50" "2015-05-07 09:03:28" "2015-05-07 09:04:25" ...

> head(profdata1)
            Date        DepthTemp            DateTime
16693 2015-05-07   0.6   11.65    2015-05-07 09:02:03
16694 2015-05-07   1.0   11.34    2015-05-07 09:02:50
16695 2015-05-07   2.0   11.02    2015-05-07 09:03:28
16696 2015-05-07   4.0   10.86    2015-05-07 09:04:25
16697 2015-05-07   6.0   10.75    2015-05-07 09:05:17
16698 2015-05-07   8.0    9.23     2015-05-07 09:06:48

Thanks in advance,
Dan

Crump, Ron

unread,
Apr 10, 2017, 9:45:48 AM4/10/17
to Dan Crocker, ggplot2
Hi Dan,

>I am trying to make the exact same plot with similar data (see below).

I couldn't see the plot in your message, but looking back at Al's query on
google groups I see that there was a suggestion from Dennis on how to
proceed. Can you expand on why that is not suitable/helpful for you?

> I have run into all of the same errors and shortcomings and hoping
>someone could share a working solution (I did not see one here).

From looking at Dennis' reply to Al, it appeared that his problems were in
the data really.

> I have tried using just the date for the x value
> and date-time - that is the only reason that both are in the dataframe.
>
>> str(profdata1)
>
>'data.frame': 791 obs. of 4 variables:
> $ Date : Date, format: "2015-05-07" "2015-05-07" "2015-05-07"
>"2015-05-07" ...
> $ Depth : num 0.6 1 2 4 6 8 10 12 14 16 ...
> $ Temp : num 11.6 11.3 11 10.9 10.8 ...
> $ DateTime: POSIXct, format: "2015-05-07 09:02:03" "2015-05-07 09:02:50"
>"2015-05-07 09:03:28" "2015-05-07 09:04:25" ...
>
>> head(profdata1)
> Date DepthTemp DateTime
>16693 2015-05-07 0.6 11.65 2015-05-07 09:02:03
>16694 2015-05-07 1.0 11.34 2015-05-07 09:02:50
>16695 2015-05-07 2.0 11.02 2015-05-07 09:03:28
>16696 2015-05-07 4.0 10.86 2015-05-07 09:04:25
>16697 2015-05-07 6.0 10.75 2015-05-07 09:05:17
>16698 2015-05-07 8.0 9.23 2015-05-07 09:06:48

This isn't all that useful. A reproducible example of where you are
featuring some data from dput would make it easier to help you. I guess
you have a lot of data points, so a small subset of time maybe.

Ron.

Dan Crocker

unread,
Apr 12, 2017, 2:39:16 PM4/12/17
to ggplot2, decr...@gmail.com, R.E....@warwick.ac.uk
Ron, 

Thanks for the reply...I am a fairly new R user, so my ability to explain why things aren't working is limited. I've attempted the suggestions in this post and others, but with no success. I attached one years worth of weekly profile data, hoping to plot it up like Al's attached "goal.PNG" The plot below is about as close as I have come to achieving the desired plot.  Rather than copying the code for the dozen or so variations of failed attempts, if you or someone else could post a working example that uses a similar dataset with x, y, and  z values (or using my data) I would greatly appreciate it. 


2015Prof.csv

Thierry Onkelinx

unread,
Apr 12, 2017, 3:06:46 PM4/12/17
to Dan Crocker, ggplot2, R.E....@warwick.ac.uk
Dear Dan,

geom_contour() works on a regular grid of x and y locations. Your dataset is irregular.

Best regards,

Thierry

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com

More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sam Albers

unread,
Apr 12, 2017, 4:06:10 PM4/12/17
to Thierry Onkelinx, Dan Crocker, ggplot2, R.E....@warwick.ac.uk
Dan - 

If I understand your question correctly I made attempts at this issue before here:


Adapting that approach to your data results in this plot:

Inline image 2

Here is the code to produce this. It is tidyverse heavy and makes use of the akima package to accomplish the interpolation:

library(tidyverse)
library(padr)
library(akima)
library(lubridate)

## Interpolation and convert to a dataframe
dpinterp <- function(df=df) {
  interp_df <- interp(x=df$DateTime_day, y=df$Depth, z=df$Temp, duplicate="strip")
  interp2xyz(interp_df, data.frame=TRUE)
}


## Read in the data, interpolate, and perform some data cleaning
ctd <- read_csv("2015Prof.csv") %>%
  thicken("day") %>%
  do(dpinterp(.)) %>%
  tbl_df() %>%
  rename(Date = x, Depth = y, Temp = z) %>%
  mutate(Date = as_date(Date, origin = lubridate::origin)) %>%
  filter(!is.na(Temp))


## Contour plot
ctd %>%
  ggplot(aes(x = Date, y = Depth, z = Temp, fill = Temp)) + 
  geom_tile() + 
  scale_y_reverse(expand = c(0,0)) +
  scale_x_date(expand = c(0, 0), date_labels = "%b", date_breaks = "1 month") +
  stat_contour(aes(fill=..level..), geom="polygon", binwidth=0.005) + 
  geom_contour(color = "white", alpha = 0.5) + 
  scale_fill_distiller( 
    palette="RdYlGn", 
    na.value="white") + 
  theme_minimal() 

This isn't a perfect solution. I'm not certain why the 0.4 depth interpolation results in a bunch of NA for temperature. Also the contour doesn't start at the shallowest depth. Still I think there is some useful stuff here.

HTH,

Sam

Thiago V. dos Santos

unread,
Apr 12, 2017, 8:22:09 PM4/12/17
to Al Kirschbaum, ggp...@googlegroups.com
Hi Al,

I tried to create a similar plot a couple years ago, but for a time series of soil moisture in eleven soil depths. My initial attempt also was to use ggplot, since I try to keep it as my essential plotting tool.

However, I never managed to get a satisfactory result, and ended up using "filled.contour". The final result was pretty good, and I think you should give it a try. You'll have to do a little data transformation though. You'll have to break down your data frame into: a) a vector containing the time stamp (which will be your x argument to the function), b) a vector with the depth labels (the y argument to the function) and c) your temperature data organized as a matrix with dimensions [number of depths; number of time steps], which will be the z argument to the filled.contour function.

I recommend following the examples provided by the function - ??filled.contour -, and let me know if you have further questions.

I hope it helps,
Greetings,
-- Thiago V. dos Santos

PhD candidate
Land and Atmospheric Science
University of Minnesota


On Monday, January 27, 2014 4:56 PM, Al Kirschbaum <aaki...@gmail.com> wrote:



Hello-

I have hourly readings of temperature at 0, 1.5, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 meters beneath the surface of the water for an entire year. I would like to create a graph like this...
Depth on y axis, time on x axis and the water temperature used for z axis.

Unfortunately, due the large size of the dataset (100k observations for a year), I cannot attach the dataset, or replicate it. I have included a snippet to at least show the general outline of the data.

data <- structure(list(date_time = structure(c(1339016400, 1339020000,
1339023600, 1339027200, 1339030800, 1339034400), class = c("POSIXct",
"POSIXt"), tzone = ""), temperature = c(21.103, 21.199, 20.96,
20.96, 21.103, 20.412), depth = c(0, 0, 0, 0, 0, 0)), .Names = c("date_time",
"temperature", "depth"), row.names = c("48730", "48731", "48732",
"48733", "48734", "48735"), class = "data.frame")


You just have to imagine another 100k records!

When I use ggplot2 and the stat_contour function, I produce the following graph:

v <- ggplot(data,aes(date_time,depth,z=temperature))
v <- v + stat_contour(geom="polygon")
v <- v + scale_fill_gradientn(colours=rev(rainbow(10)))
v <- v + geom_tile(aes(fill=temperature))
v <- v + scale_y_reverse()
v





This produces a very choppy graph with no data between the depths. Of course, part of the difference between the two is that the first graph uses modeled data to fill in the gaps between depths. I believe it also models more time steps, to make a smoother graph. I tried modeling the data using the loess function which helps smooth the data, unfortunately it creates an incredibly large dataset, bumping into memory limits on my machine. Not to mention, it takes minutes to render millions of values.

Maybe I'm using the wrong tool within R to produce this type of plot. I enjoy using ggplot and would like to continue to do so. I figured this group would have a solution.

Thanks for any help or suggestions.

-al


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Jason Law

unread,
Apr 12, 2017, 9:34:54 PM4/12/17
to Dan Crocker, ggplot2
I answered a similar question on stack overflow recently: http://stackoverflow.com/questions/42973460/interpolation-and-plotting-of-2d-spatial-timeseries-data-on-an-irregular-grid-wi/42984201#42984201

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Crocker

unread,
Apr 13, 2017, 11:44:03 AM4/13/17
to Jason Law, ggplot2
Jason and Sam,

Thanks for your assistance. I was able to get both of your methods working with my data, although in Jason's method the resolution is a bit more granular and date time values are numerical, which makes the axis labels read as decimal years instead of month
  
Thiago- I have seen the examples using filled_contour and I tried that method as well with no success. I really like the result of filled_contour, but  I just couldn't get my data in the right format to work. If you have any insight into how I would manipulate my dataset to use filled_contour I would love to learn that method as well. 

Regards,
Dan


You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.

Jason Law

unread,
Apr 14, 2017, 12:14:02 PM4/14/17
to Dan Crocker, ggplot2
Hi Dan,

I think you may get the most mileage from a combination of the solutions. Sam's is definitely a more elegant ggplot approach. However, I've had much better luck with MBA with sparse data and big data than akima, which I've used for many years. When akima fails to give a good looking image, the MBA package always seems to do better.

Hope that helps,

J

To unsubscribe: email ggplot2+u...@googlegroups.com
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.

Sam Albers

unread,
Apr 20, 2017, 3:33:06 PM4/20/17
to Jason Law, Dan Crocker, ggplot2
I was curious to see how Jason's approach with the MBA package lined up with mine. I had been using a linear interpolation but was curious if I could get AKIMA to produce a spline interpolation that looked about the same. AFAIK the only way to accomplish this in AKIMA was to add some jitter to avoid collinearity. I iteratively found a number that worked about right (0.001) in this case. I'm not totally sure how to judge this as the AKIMA package seems to give you more control over a spline interpolation though in my experience the linear interpolation is more common in oceanography/limnology where plots like this are common. 

Visually the AKIMA linear interpolation appears to be the nicest to me though the MBA is about right as well. 

Whatever the case, I went ahead and did this and figured it might be useful to leave here. Plot first then code below. The code is a bit messy so any input would be welcomed:

Inline image 1


library(tidyverse)
library(padr)
library(akima)
library(lubridate)
library(MBA)
library(gridExtra)


############
### DATA ###
############

data_df <- read_csv("2015Prof.csv") %>%
  thicken("day") %>%
  mutate(Date = decimal_date(DateTime_day))

#############################
### AKIMA solution linear ###
#############################
## Interpolation and convert to a dataframe
dpinterp <- function(df=df) {
  interp_df <- interp(x=df$DateTime_day, y=df$Depth, z=df$Temp, duplicate="strip", linear = TRUE, nx = 100, ny = 100)
  interp2xyz(interp_df, data.frame=TRUE)
}


## Read in the data, interpolate, and perform some data cleaning
ctd <- data_df %>%
  do(dpinterp(.)) %>%
  tbl_df() %>%
  rename(Date = x, Depth = y, Temp = z) %>%
  mutate(Date = as_date(Date, origin = lubridate::origin)) %>%
  filter(!is.na(Temp))


## Contour plot
akima_plt_linear <- ctd %>%
  ggplot(aes(x = Date, y = Depth, z = Temp, fill = Temp)) +
  geom_tile() +
  scale_y_reverse(expand = c(0,0)) +
  scale_x_date(expand = c(0, 0), date_labels = "%b", date_breaks = "1 month") +
  stat_contour(aes(fill=..level..), geom="polygon", binwidth=0.005) +
  geom_contour(color = "white", alpha = 0.5) +
  scale_fill_distiller(
    palette="RdYlGn",
    na.value="white") +
  labs(title = "AKIMA package solution - linear") +
  theme_minimal()



#############################
### AKIMA solution spline ###
#############################
## Interpolation and convert to a dataframe
dpinterp <- function(df=df) {
  interp_df <- interp(x=df$DateTime_day, y=df$Depth, z=df$Temp, duplicate="strip", linear = FALSE, jitter = 0.001, nx = 100, ny = 100)
  interp2xyz(interp_df, data.frame=TRUE)
}


## Read in the data, interpolate, and perform some data cleaning
ctd <- data_df %>%
  do(dpinterp(.)) %>%
  tbl_df() %>%
  rename(Date = x, Depth = y, Temp = z) %>%
  mutate(Date = as_date(Date, origin = lubridate::origin)) %>%
  filter(!is.na(Temp))


## Contour plot
akima_plt_spline <- ctd %>%
  ggplot(aes(x = Date, y = Depth, z = Temp, fill = Temp)) +
  geom_tile() +
  scale_y_reverse(expand = c(0,0)) +
  scale_x_date(expand = c(0, 0), date_labels = "%b", date_breaks = "1 month") +
  stat_contour(aes(fill=..level..), geom="polygon", binwidth=0.005) +
  geom_contour(color = "white", alpha = 0.5) +
  scale_fill_distiller(
    palette="RdYlGn",
    na.value="white") +
  labs(title = "AKIMA package solution - spline") +
  theme_minimal()

####################
### MBA solution ###
####################

mba <- mba.surf(df[,c('Date', 'Depth', 'Temp')], no.X = 100, no.Y = 100)
dimnames(mba$xyz.est$z) <- list(mba$xyz.est$x, mba$xyz.est$y)

df2 <- as.data.frame(mba$xyz.est$z) %>%
  tbl_df() %>%
  rownames_to_column(., var = "Date") %>%
  gather(Depth, Temp, -Date) %>%
  mutate(Depth = as.numeric(Depth), Date = as.numeric(Date)) %>%
  mutate(Date = dmy(format(date_decimal(Date), "%d-%m-%Y"))) %>%
  filter(!is.na(Temp))

mba_plt <- df2 %>%
  ggplot(aes(x = Date, y = Depth, z = Temp, fill = Temp)) + 
  geom_tile() + 
  scale_y_reverse(expand = c(0,0)) +
  scale_x_date(expand = c(0, 0), date_labels = "%b", date_breaks = "1 month") +
  stat_contour(aes(fill=..level..), geom="polygon", binwidth=0.005) + 
  geom_contour(color = "white", alpha = 0.5) + 
  scale_fill_distiller( 
    palette="RdYlGn", 
    na.value="white") + 
  labs(title = "MBA package solution") +
  theme_minimal() 

######################
### Combine the plots ###
######################

gAs <- ggplotGrob(akima_plt_spline)
gAl <- ggplotGrob(akima_plt_linear)
gM <- ggplotGrob(mba_plt)

gridExtra::grid.arrange(gAs,gAl,gM)

J


You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility
 
To post: email ggp...@googlegroups.com

More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+unsubscribe@googlegroups.com.

Bill Perry

unread,
May 2, 2017, 5:50:08 AM5/2/17
to ggplot2, jason...@gmail.com, decr...@gmail.com
Hi, This is excellent and just what I have been looking for - in the code there was a small error I think :

mba <- mba.surf(df[,c('Date', 'Depth', 'Temp')], no.X = 100, no.Y = 100)

the df should be data_df 

atleast I think and that did work.... as the df did not.

I was going to play with it a bit more to get the matlab like colors as in the post referred to above:

scale_fill_gradientn(colours = matlab.like2(7))
 
Reply all
Reply to author
Forward
0 new messages