## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
has_tk <- capabilities("tcltk") && (
  !grepl("darwin", R.version$os, ignore.case = TRUE) ||
  capabilities("X11")
)

## ----setup--------------------------------------------------------------------
library(rbcmodel)
#basic plot
Rbc_wheat <- Enzyme("aestivum_Iñiguez_2021",enzyme_name="wheat")
wheat_DH<-DHScale("aestivum_orr_2016_dH",data="abridged")
wheat_DH<-modify_DHScale(wheat_DH,Ko_dH=26.7)
wheat_carbon<-CO2_dependence(Rbc_wheat,wheat_DH)
CO2_seq<-O2_seq<-seq(0,1000,by=10)
temp_seq<-seq(0,40,by=.1)
wheat_grid<-make_4D_grid(wheat_carbon,CO2_seq,O2_seq,temp_seq,var_names=c("CO2","O2","T","wheat"))
s1<-slice_4D_grid(wheat_grid,dim=3,25)
s2<-slice_4D_grid(wheat_grid,dim=2,300)

## ----nice_labels, eval = has_tk-----------------------------------------------
plot_slice_3D(s2,contours=c(2,4,6,8),xlabel=expression(CO[2]~(μM)),ylabel="T (°C)")
#plot_slice_3D(s2,contours=c(2,4,6,8),xlabel=expression(CO[2]~(mu*M)),ylabel="T (°C)") will create mu just as easily.

## ----shifting_color_scale_boundaries, eval = has_tk---------------------------
plot_slice_3D(s1,contours=c(1.5,2,2.5),xlabel=expression(CO[2]~(μM)),ylabel=expression(O[2]~(μM)))
plot_slice_3D(s1,contours=c(1.5,2,2.5),xlabel=expression(CO[2]~(μM)),ylabel=expression(O[2]~(μM)), cmax=5)

## ----color_palette_from_scratch, eval = has_tk--------------------------------
green_ex<-plot3D::ramp.col(c("white","green"),n=125)
#print color scale for visualization of data structure
green_ex
plot_slice_3D(s1,contours=c(1.5,2,2.5),xlabel=expression(CO[2]~(μM)),ylabel=expression(O[2]~(μM)),colors=green_ex)

## ----unused_variable, eval = has_tk-------------------------------------------
#passing an unused variable to image2D()
plot_slice_3D(s1,contours=c(1.5,2,2.5),xlabel=expression(CO[2]~(μM)),ylabel=expression(O[2]~(μM)),rasterImage=TRUE)

## ----add_title, eval = has_tk-------------------------------------------------
plot_slice_3D(s1,contours=c(1.5,2,2.5),xlabel=expression(CO[2]~(μM)),ylabel=expression(O[2]~(μM)))
title("My title")

## ----add_line, eval = has_tk--------------------------------------------------
plot_slice_3D(s1,contours=c(1.5,2,2.5),xlabel=expression(CO[2]~(μM)),ylabel=expression(O[2]~(μM)))
abline(h=300)

## ----permute_4D_grid----------------------------------------------------------
g2 <- permute_4D_grid(wheat_grid, c(3, 1, 2))
names(g2)

## ----dim_2_slice_after_permute, eval = has_tk---------------------------------
s3 <- slice_4D_grid(g2, dim=2, val=500)
plot_slice_3D(s3, contours=c(2, 4, 6),xlabel=expression("T (°C)"),ylabel=expression(O[2]~(μM)))

## ----dim_3_slice_after_permute, eval = has_tk---------------------------------
s3 <- slice_4D_grid(g2, dim=3, val=500)
plot_slice_3D(s3, contours=c(2, 4, 6), xlabel=expression("T (°C)"), ylabel=expression(CO[2]~(μM)))

