How to scale the points on this plot to a different variable?

26 Views Asked by At

I made a Temperature-Salinity plot and need to scale the size of the points to a different variable. A temperature-salinity plot is a plot that takes the temperature and salinity and finds the density and plots it based on three values. In the example picture, the curved lines represent density.

Here is what a row of my data looks like:

Temperature Salinity pCO2
23.253 36.929 352.7

Heres my code of my plot (this code basically makes an empty graph and you have to manually make each point an object and apply it to the graph):

#FORMING GRAPH FRAME:
library(shape)
library(marelac)
library(plot3D)
S.seq <- seq(from = 20, to = 40, length.out = 100)
t.seq <- seq(from = 20, to = 40, length.out = 100)
sig.mat <- outer(S.seq, t.seq, FUN = function(S, t) sw_dens(S = S, t = t) - 1000)
#GRAPH FRAME:
  contour2D(x = S.seq, y = t.seq, z = sig.mat, lwd = 3,
            xlab = 'Salinity', ylab = 'Temperature (°C)',main = 'Surface T-S')

Here is an example of making the objects for the graph:

t2s = 23.253
S2s = 36.929

And then apply those objects to the graph:

scatter2D(S2s, t2s, pch=20, col ='darkgreen', cex= 1, add= TRUE, 
          clim = range(sig.mat), colkey = FALSE)

Here is an example of a final product with all the points on it: plot

But I need the points to be scaled to the pCO2 value. Or if you know an easier way to do this type of plot, any feedback is helpful.

0

There are 0 best solutions below