rm(list=ls())
library(ggplot2)
library(ggpubr)
library(scales)
library(lubridate)
##
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
##
## date, intersect, setdiff, union
library(readr)
##
## Attaching package: 'readr'
## The following object is masked from 'package:scales':
##
## col_factor
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(chron)
##
## Attaching package: 'chron'
## The following objects are masked from 'package:lubridate':
##
## days, hours, minutes, seconds, years
library(plotly)
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
library(dplyr)
library(tidyr)
library(taRifx)
##
## Attaching package: 'taRifx'
## The following object is masked from 'package:plotly':
##
## distinct
## The following objects are masked from 'package:dplyr':
##
## between, distinct, first, last
Read in data
data<-read.csv(
"https://raw.githubusercontent.com/Cmwegener/thesis/master/data/experiment/mesocosm.unit.oog.csv",
header = TRUE
)
Changing “treatment” from integer to character so that it plots as discrete values
data$treatment<-as.character(data$treatment)
3D plot
plot_ly(
data,
x = ~ unit_ph_c,
y = ~ unit_sal_hach,
z = ~ avg.oo.disc,
marker=list(size = 5),
colors = c('aquamarine4', 'salmon', "goldenrod1", 'dark green')
) %>%
layout(title = "Effect of salinity and pH on oogonia released per unit") %>%
add_markers(color=~treatment) %>%
layout(scene = list(
xaxis = list(title = 'pH'),
yaxis = list(title = 'Salinity'),
zaxis = list(title = 'Oogoinia released')
))
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
Trying different marker shapes instead
https://plotly.com/r/reference/#scatter-marker-symbol
plot_ly(
data,
x = ~ unit_ph_c,
y = ~ unit_sal_hach,
z = ~ avg.oo.disc,
marker=list(size = 5),
symbol=~treatment,
symbols = c("circle-open", "cross", "square-open", "triangle-se-open")
)%>%
layout(title = "Effect of salinity and pH on oogonia released per unit",
scene = list(
xaxis = list(title = 'pH'),
yaxis = list(title = 'Salinity'),
zaxis = list(title = 'Oogoinia released')
))
## No trace type specified:
## Based on info supplied, a 'scatter3d' trace seems appropriate.
## Read more about this trace type -> https://plot.ly/r/reference/#scatter3d
## No scatter3d mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
Not sure why the triangles arent’ working. I like having different shapes though
Shading to planes to make it clearer?
fig<-plot_ly(
data,
x = ~ unit_ph_c,
y = ~ unit_sal_hach,
z = ~ avg.oo.disc,
marker=list(size = 5),
symbol=~treatment,
symbols = c("circle-open", "cross", "square-open", "triangle-se-open")
)%>%
layout(title = "Effect of salinity and pH on oogonia released per unit",
scene = list(
xaxis = list(title = 'pH'),
yaxis = list(title = 'Salinity'),
zaxis = list(title = 'Oogoinia released')
))
axx <- list(
backgroundcolor="lightgrey",
gridcolor="black",
showbackground=TRUE,
zerolinecolor="black"
)
axy <- list(
backgroundcolor="lightgrey",
gridcolor="black",
showbackground=TRUE,
zerolinecolor="black"
)
axz <- list(
backgroundcolor="rgb(230, 230,200)",
gridcolor="rgb(255,255,255)",
showbackground=TRUE,
zerolinecolor="rgb(255,255,255"
)
fig %>% layout(scene = list(xaxis=axx,yaxis=axy,zaxis=axz))
## No trace type specified:
## Based on info supplied, a 'scatter3d' trace seems appropriate.
## Read more about this trace type -> https://plot.ly/r/reference/#scatter3d
## No scatter3d mode specifed:
## Setting the mode to markers
## Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode