function plotDistribution(vector, nSample, color, xSpacing)
% nSample = round(sqrt(length(vector)));
% nSample = 100;
% error('jap')

if ~exist('xSpacing', 'var') || isempty(xSpacing)
    xPlotVector = sort(vector);
    % yVector = xVector*0 + 1/length(xVector);
    boundaryIdxVector = [1:nSample:(length(xPlotVector)-1) length(xPlotVector)];
    
    xPlotVector = 0.5*xPlotVector(boundaryIdxVector(2:end)) + ...
        0.5*xPlotVector(boundaryIdxVector(1:end-1));
    yPlotVector = (1/length(xPlotVector))*...
        (boundaryIdxVector(2:end) - boundaryIdxVector(1:end-1)) ./ ...
        (xPlotVector(boundaryIdxVector(2:end)) - ...
        xPlotVector(boundaryIdxVector(1:end-1)));
    
    yPlotVector = yPlotVector .* xPlotVector.^3;
    
else
    xPlotVector = 0.5*(xSpacing(1:(end-1)) + xSpacing(2:end));
    yPlotVector = xPlotVector*0;
    for iBin = 1:length(xPlotVector)
        filter = vector >= xSpacing(iBin) & vector < xSpacing(iBin+1);
        yPlotVector(iBin) = sum(filter) / (xSpacing(iBin+1) - xSpacing(iBin));
    end
end

plot(xPlotVector, yPlotVector / length(vector), 'rx-', 'color', color, 'lineWidth', 3)