Scatter plots for a large dataset with 2 grouping variables
Show older comments
I have a large dataset with 4 variables. I want to make scatter plots for using two of the variables (x = date, y = d18O), GROUPED by the other two variables (site and depth). Specifically, I want there to be a single plot for each SITE, with different colored dataseries (x, y) based on DEPTH.
My code so far:
tT=readtable("data1.csv", "VariableNamingRule","preserve");
tT.Properties.VariableNames(2)={'Site'}; % shorten to be more convenient to use
G=grpstats(tT,{'Site','Depth'},{'mean','median','std'},'DataVars',{'Date','d18O'});
hSc=rowfun(@doit,tT,'GroupingVariables',{'Site'},'InputVariables',{'Date','d18O','Site','Depth'},'OutputFormat','uniform');
function h=doit(x,y,s,d)
figure
h=gscatter(x,y,d);
xlabel('Date'),ylabel('d18O')
end
This code produces one graph that looks like what I want, but then I get an error :
Error using tabular/rowfun
The function 'doit' returned a non-scalar value when applied to the 1st group of rows.
Error in lysimeter_processing_code_v2 (line 6)
hSc=rowfun(@doit,tT,'GroupingVariables',{'Site'},'InputVariables',{'Date','d18O','Site','Depth'},'OutputFormat','uniform');
Any help appreciated!
*note attached dataset is only a tiny fraction of actual data, this code will be used for a very large dataset when I am done. (hence why I need to automate making the figures)
*in final dataset, each SITE will contain data for up to 4 DEPTHS
Accepted Answer
More Answers (0)
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



