In this article, we will discuss the theory behind converting wave spectra to scatter plots using R programming language. This conversion is crucial in various fields such as oceanography and offshore engineering.
Let $Z_l$ be the list of sea state spectra and associated durations, for $l = 1,\ldots,k$ where $k$ is the number of sea states. The probability of occurrence of sea state $q$ is given by:
$$P(Z_q) = \frac{D_q}{\displaystyle \sum_l D_l}$$
The absolute values of $D_l$ are not important here, only their relative values.
Regular Wave Bins
The wave height bins are denoted by $[H_i\low,H_i\upp]$ for $i=1,\ldots,m$. The first bin is taken to be:
$$[H_1\low,H_1\upp] = [0,\ \tfrac12(H_1+H_2)]$$
The last bin is taken to be:
$$[H_m\low,H_m\upp] = [\tfrac12(H_{m-1}+H_m),\ H_m+\tfrac12(H_m-H_{m-1})]$$
so that $H_m$ falls in the middle of the last bin. Finally, the intermediate bins are chosen to be:
$$[H_i\low,H_i\upp] = [\tfrac12(H_{i-1}+H_i),\ \tfrac12(H_i+H_{i+1})]$$
for $i = 2,\ldots,m-1$. The wave period bins $[T_j\low, T_j\upp]$ for $j=1,\ldots,n$, are chosen in an analogous fashion.
Joint Probability for Individual Waves
This section is based on Barltrop and Adams' work. Following their lead, we use the formula of Longuet-Higgins (1983) giving the joint probability density $p(R,S,Z)$ of individual waves in a given random sea state as:
$$p(R,S,Z) = L(\nu)\ \exp\left[-R^2\left(1+\frac{(1-1/S)^2}{\nu^2}\right)\right]\ \frac{2R^2}{S^2\nu\sqrt\pi}$$
where $Z$ is the spectrum of given random sea state, and other variables are defined as in the reference.
Individual Wave Scatter
For each sea state $Z_l$, we can calculate the probability of occurrence of each individual wave height and period bin, denoted by $P(\Bij\vert Z_l)$, as:
$$P(\Bij\vert Z_l) = \iint p(R,S,Z_l),dS,dR$$
where the double integral is evaluated over the region $R_i\low \leq R \leq R_i\upp$, $S_j\low \leq S \leq S_j\upp$.
Scatterplot in R
Now, let's create a simple dataframe and produce a scatterplot:
a <- c(-1,-2,-1.5)
b <- c(1,3,2)
df <- data.frame(a,b)
plot(df$a , df$b)
Result:
We can see the scatterplot with minus signs before the x-axis labels. To remove these minus signs, we can multiply the labels by -1:
plot(df$a*-1 , df$b)
Alternatively, we can create another column in the data frame for the labels:
df$x_label <- df$a * -1
plot(df$a , df$b, xlab="x", ylab="y")
axis(1, at=df$x_label, labels=as.character(df$x_label))
In this example, we create a new column x_label
in the data frame and then use it to label the x-axis of the scatterplot.