dpb <
no...@non.net> wrote in message <kd6tu5$v3u$
2...@speranza.aioe.org>...
Thank you for the help. It turned out to be not easily workable. There was a host of problems including the y-axis on the main plot not clearing, not being able to include an lsline, inserted text did not work properly, etc.
I did finally find something that worked with a bit of tweaking. I am including the code incase any one else has a similar issue and wants complete working code to play with.
The one issue with this is that the text that insets and updates with each refresh is tied to the inset plot rather than the main plot. It was fine for this, but could be a problem in other cases.
As I said this is meant to be a demonstration of several things, and is also meant to create discussion.
% Source: "Gun homicides and gun ownership listed by country"
% Simon Rogers, The Gaurdian, 22 July, 2013
%
http://www.guardian.co.uk/news/datablog/2012/jul/22/gun-homicides-ownership-world-list
% Data extracted from .xls spreadsheet and should be taken as "essentially" accurate
clear A B C
%gun/per g_deaths/person
A =...
[0.303 0.00000000000000000
0.248 0.00000000000000000
0.119 0.00000000000000000
0.014 0.00000000000000000
0.004 0.00000000000000000
0.006 0.00000009295774648
0.007 0.00000021875000000
0.005 0.00000022727272727
0.011 0.00000030196078431
0.007 0.00000031111111111
0.192 0.00000036915977697
0.313 0.00000044714285714
0.312 0.00000057473684211
0.055 0.00000068750000000
0.062 0.00000074764705882
0.076 0.00000080000000000
0.147 0.00000081666666667
0.073 0.00000087600000000
0.013 0.00000089215686275
0.135 0.00000100000000000
0.038 0.00000105555555556
0.019 0.00000114000000000
0.073 0.00000123380281690
0.035 0.00000132758620690
0.150 0.00000147540983607
0.226 0.00000171027027027
0.083 0.00000184444444444
0.071 0.00000189333333333
0.303 0.00000191496000000
0.163 0.00000203750000000
0.104 0.00000208000000000
0.066 0.00000212903225806
0.304 0.00000218880000000
0.092 0.00000224390243902
0.010 0.00000230769230769
0.048 0.00000237798165138
0.015 0.00000259459459459
0.225 0.00000261000000000
0.120 0.00000276923076923
0.042 0.00000282404347826
0.219 0.00000288157894737
0.125 0.00000296052631579
0.008 0.00000327804878049
0.190 0.00000339285714286
0.217 0.00000388315789474
0.085 0.00000415555555556
0.316 0.00000417571428571
0.039 0.00000420588235294
0.014 0.00000434000000000
0.453 0.00000453000000000
0.173 0.00000461333333333
0.115 0.00000474603174603
0.086 0.00000501666666667
0.073 0.00000530909090909
0.016 0.00000533333333333
0.308 0.00000535517587940
0.378 0.00000557704918033
0.009 0.00000560000000000
0.153 0.00000655714285714
0.062 0.00000658750000000
0.364 0.00000661818181818
0.172 0.00000668888888889
0.119 0.00000708900000000
0.125 0.00000743055555556
0.457 0.00000766147058824
0.044 0.00000776827586207
0.035 0.00000834473684211
0.210 0.00000868000000000
0.014 0.00000980000000000
0.005 0.00001040000000000
0.089 0.00001083478260870
0.241 0.00001229591836735
0.017 0.00001288909090909
0.043 0.00001340166666667
0.013 0.00001365000000000
0.015 0.00001455000000000
0.065 0.00001547619047619
0.086 0.00001783703703704
0.107 0.00002158342857143
0.006 0.00002258823529412
0.318 0.00002688545454545
0.034 0.00002856000000000
0.078 0.00002971428571429
0.888 0.00003008017777778
0.102 0.00003093569620253
0.099 0.00004627674418605
0.013 0.00006289189189189
0.044 0.00006578000000000
0.077 0.00006588860759494
0.170 0.00007922000000000
0.047 0.00008856487179487
0.150 0.00010944193548387
0.146 0.00011281818181818
0.053 0.00016211764705882
0.217 0.00017639000000000
0.127 0.00017756521008403
0.051 0.00018337333333333
0.080 0.00018694339622642
0.188 0.00018975466666667
0.100 0.00023448275862069
0.059 0.00027400037037037
0.016 0.00027809523809524
0.058 0.00035467000000000
0.131 0.00039768424242424
0.081 0.00040688372093023
0.107 0.00041730000000000
0.062 0.00064492400000000];
B=[{'Iceland'}
{'Bahrain'}
{'Malta'}
{'Brunei'}
{'Solomon Islands'}
{'Japan'}
{'Romania'}
{'Singapore'}
{'Korea, South'}
{'Lithuania'}
{'Qatar'}
{'Norway'}
{'France'}
{'Hungary'}
{'England and Wales'}
{'Algeria'}
{'Mauritius'}
{'Israel'}
{'Poland'}
{'Slovenia'}
{'Turkmenistan'}
{'Mongolia'}
{'Belarus'}
{'Azerbaijan'}
{'Australia'}
{'New Zealand'}
{'Slovakia'}
{'Moldova'}
{'Germany'}
{'Czech Republic'}
{'Spain'}
{'Ukraine'}
{'Austria'}
{'Estonia'}
{'Tajikistan'}
{'Cuba'}
{'Malaysia'}
{'Greece'}
{'Denmark'}
{'India'}
{'Northern Ireland'}
{'Armenia'}
{'Nepal'}
{'Latvia'}
{'Croatia'}
{'Portugal'}
{'Sweden'}
{'Netherlands'}
{'Congo, Dem Rep'}
{'Finland'}
{'Bosnia and Herzegovina'}
{'Jordan'}
{'Ireland'}
{'Georgia'}
{'Liberia'}
{'Canada'}
{'Serbia'}
{'Kyrgyzstan'}
{'Luxembourg'}
{'Bulgaria'}
{'Cyprus'}
{'Belgium'}
{'Italy'}
{'Turkey'}
{'Switzerland'}
{'Taiwan'}
{'Egypt'}
{'Lebanon'}
{'Uganda'}
{'Bangladesh'}
{'Zambia'}
{'Macedonia'}
{'Vietnam'}
{'Cambodia'}
{'Kazakhstan'}
{'Sri Lanka'}
{'Maldives'}
{'Albania'}
{'Chile'}
{'Sierra Leone'}
{'Uruguay'}
{'West Bank & Gaza'}
{'Barbados'}
{'United States'}
{'Argentina'}
{'Costa Rica'}
{'Ecuador'}
{'Zimbabwe'}
{'Nicaragua'}
{'Paraguay'}
{'Philippines'}
{'Mexico'}
{'Guyana'}
{'Bahamas'}
{'Panama'}
{'South Africa'}
{'Dominican Republic'}
{'Brazil'}
{'Peru'}
{'Belize'}
{'Colombia'}
{'Trinidad and Tobago'}
{'El Salvador'}
{'Guatemala'}
{'Jamaica'}
{'Venezuela'}
{'Honduras'}];
c = 1;
C(1,1)=[{num2str(corr(A(:,1),A(:,2))^2)}];
while true
subplot(1,1,1)
plot(A(:,1),A(:,2),'*'),%hold on
title('Scatter plot and Box Plot of Gun Density vs. Gun Deaths')
xlabel('Gun Density')
ylabel('Shooting Deaths per Person')
lsline
xt = get(gca,'xtick');
yt = get(gca,'ytick');
axes('pos',[.61 .55 .1 .3])
boxplot(A(:,2),'widths',1/2)
set(gca,'xticklabel','[]')
text(1.6,1.2*max(A(:,2)),[C],'verticalalignment','top')
text(1.25,1.23*max(A(:,2)),'R^2 = ','verticalalignment','top')
my = mean(A(:,2));
outlier = quantile(A(:,2),.75) + 1.5*iqr(A(:,2));
z = find(A(:,2) >= outlier);
if isempty(z) == false
[v ind] = sort(A(:,2),'descend');
else
break
end
r(c) = corr(A(:,1),A(:,2));
C(1,1)=[{num2str(r(c)^2)}];
C(c+1,1) = B(ind(1));
c = c+1;
A(ind(1),:) = [];
B(ind(1)) = [];
pause(1)
end