function LDLplot(X1, Y1, S1, C1)
%CREATEFIGURE(X1,Y1,S1,C1)
% X1: scatter x
% Y1: scatter y
% S1: scatter s
% C1: scatter c
% Auto-generated by MATLAB on 21-Sep-2010 11:16:44
% Copyright 2010 - 2011 MathWorks, Inc.
% Create figure
figure1 = figure;
% Create axes
axes1 = axes('Parent',figure1);
% Uncomment the following line to preserve the X-limits of the axes
% xlim(axes1,[3.6 5]);
% Uncomment the following line to preserve the Y-limits of the axes
% ylim(axes1,[1 5]);
box(axes1,'on');
hold(axes1,'all');
% Create scatter
scatter1 = scatter(X1,Y1,S1,C1,'MarkerEdgeColor',[0 0.498039215803146 0],...
'Marker','.',...
'Parent',axes1,...
'DisplayName','data 1');
% Create xlabel
xlabel('LDL C at BL');
% Create ylabel
ylabel('LDL C at 12 weeks');
% Get xdata from plot
xdata1 = get(scatter1, 'xdata');
% Get ydata from plot
ydata1 = get(scatter1, 'ydata');
% Make sure data are column vectors
xdata1 = xdata1(:);
ydata1 = ydata1(:);
% Get axes ylim
axYLim1 = get(axes1, 'ylim');
% Get axes xlim
axXLim1 = get(axes1, 'xlim');
% Find the mean
xmean1 = mean(xdata1);
% Get coordinates for the mean line
meanValue1 = [xmean1 xmean1];
% Plot the mean
statLine1 = plot(meanValue1,axYLim1,'DisplayName',' x mean',...
'Parent',axes1,...
'Tag','mean x',...
'LineWidth',3,...
'LineStyle','--',...
'Color',[1 0 0]);
% Set new line in proper position
setLineOrder(axes1, statLine1, scatter1);
% Find the mean
ymean1 = mean(ydata1);
% Get coordinates for the mean line
meanValue2 = [ymean1 ymean1];
% Plot the mean
statLine2 = plot(axXLim1,meanValue2,'DisplayName',' y mean',...
'Parent',axes1,...
'Tag','mean y',...
'LineWidth',3,...
'LineStyle','-.',...
'Color',[1 0 0]);
% Set new line in proper position
setLineOrder(axes1, statLine2, scatter1);
% Create legend
legend(axes1,'show');
%-------------------------------------------------------------------------%
function setLineOrder(axesh1, newLine1, associatedLine1)
%SETLINEORDER(AXESH1,NEWLINE1,ASSOCIATEDLINE1)
% Set line order
% AXESH1: axes
% NEWLINE1: new line
% ASSOCIATEDLINE1: associated line
% Get the axes children
hChildren = get(axesh1,'Children');
% Remove the new line
hChildren(hChildren==newLine1) = [];
% Get the index to the associatedLine
lineIndex = find(hChildren==associatedLine1);
% Reorder lines so the new line appears with associated data
hNewChildren = [hChildren(1:lineIndex-1);newLine1;hChildren(lineIndex:end)];
% Set the children:
set(axesh1,'Children',hNewChildren);