Skip to content

Commit 5c3db9f

Browse files
Added to geoplotFS 'Name',Value bsb
geoplotAPP now is called with 4 input arguments geoplotAPP(Ztable,score,ShapeFile,bsb) biplotAPP has been modified in order to call geoplotAPP for selected units in presence of the Shape file when check box brush units is selected
1 parent 556a854 commit 5c3db9f

File tree

4 files changed

+69
-89
lines changed

4 files changed

+69
-89
lines changed

toolbox/+aux/computePCA.m

Lines changed: 3 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -210,86 +210,9 @@
210210
else
211211
end
212212

213+
% Show the geoplot using the Shape file
213214
if ~isempty(ShapeFile)
214-
geoplotAPP(Ztable,score,ShapeFile)
215+
geoplotAPP(Ztable,score,ShapeFile,bsb)
215216
end
216-
217-
218-
% % ShapeFile
219-
% if ~isempty(ShapeFile)
220-
%
221-
%
222-
% delete(findobj(0, 'type', 'figure','tag','pl_geoplot'));
223-
% figure('Name','geoplot','tag','pl_geoplot')
224-
% % Specify the variable for which the colors have to be set
225-
% colorIntensity = score(:,1);
226-
% Xgeotable = readgeotable(ShapeFile);
227-
%
228-
% % Define a colorbar from green to red
229-
% numColors=50;
230-
% customGradient = interp1([0;1],[0 1 0; 1 0 0],linspace(0,1,numColors));
231-
%
232-
%
233-
% % Check if Mapping toolbox is installed
234-
% instTOO=struct2table(ver);
235-
% if any(string(instTOO{:,1})=="Mapping Toolbox")
236-
%
237-
% geoaxes
238-
% % Add to the geotable the Variable which contains the colors
239-
% Xgeotable.ColorVar=colorIntensity;
240-
% geoplot(Xgeotable,'ColorVariable','ColorVar');
241-
% colormap(customGradient);
242-
% h=colorbar;
243-
% h.Label.String='Color based on first PC';
244-
% geobasemap('topographic')
245-
%
246-
% % Add labels in the centroids of the shapes
247-
% % estract XY pairs coords of enclosing poligons for each row of input table
248-
% Xtab= geotable2table(Xgeotable, ["X" "Y"]);
249-
% % Obtain the averate latitute and longitude for each row
250-
% info = shapeinfo(ShapeFile);
251-
% proj = info.CoordinateReferenceSystem;
252-
% arrlonglat=zeros(n,2);
253-
% for i = 1:n
254-
% [lat, lon] = projinv(proj, Xtab.X{i},Xtab.Y{i}); % Convert to lat/lon
255-
% arrlonglat(i,1:2)=[mean(lat,'omitmissing') mean(lon,'omitmissing')];
256-
% end
257-
%
258-
% % Show the labels
259-
% text(arrlonglat(:,1), arrlonglat(:,2),rownames)
260-
%
261-
% else % mapping toolbox is not installed
262-
%
263-
% fc=customGradient(round(rescale(colorIntensity,1,numColors)),:);
264-
% polygon=mapshow(Xgeotable, "FaceAlpha",0.9);
265-
% for i=1:n
266-
% set(polygon.Children(i), 'FaceColor', fc(i,:),"FaceAlpha",0.9);
267-
% end
268-
% colormap(customGradient);
269-
% rang=[min(colorIntensity) max(colorIntensity)];
270-
% h=colorbar;
271-
% h.Label.String='Color based on first PC';
272-
% soglie=linspace(min(rang),max(rang),6);
273-
% valori=(soglie-min(soglie))/(max(soglie)-min(soglie));
274-
% h.Ticks=valori;
275-
% h.TickLabels=string(soglie);
276-
%
277-
% % Add labels in the centroids of the shapes
278-
% arrlonglat=zeros(n,2);
279-
% % estract XY pairs coords of enclosing poligons for each row of input table
280-
% Xtab= geotable2table(Xgeotable, ["X" "Y"]);
281-
%
282-
% for i=1:n
283-
% % prima creiamo degli oggetti poligonali
284-
% polObj= polyshape(Xtab.X{i,1}, ...
285-
% Xtab.Y{i,1});
286-
% [centX,centY]=centroid(polObj);
287-
% % popoliamo i vettori
288-
% arrlonglat(i,1:2)=[centX centY];
289-
% end
290-
% text(arrlonglat(:,1), arrlonglat(:,2),rownames)
291-
%
292-
%
293-
% end
294-
% end
217+
295218
end

toolbox/graphics/biplotAPP.mlapp

-1.88 KB
Binary file not shown.

toolbox/graphics/geoplotAPP.mlapp

3.02 KB
Binary file not shown.

toolbox/multivariate/geoplotFS.m

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
function geoplotFS(Y,score,ShapeFile)
1+
function geoplotFS(Y,score,ShapeFile, varargin)
22
%geoplotFS calls geoplotAPP.mlapp to show an interactive geoplot with polygons
33
%
44
%<a href="matlab: docsearchFS('geoplotFS')">Link to the help function</a>
5-
%
65
%
7-
% In the app it is also possible choose the variabile of Y to show, the
6+
%
7+
% In the app it is also possible choose the variable of Y to show, the
88
% type of plot (i.e. in latitude and longitude coordinates or in the
99
% original coordinates of ShapeFile), the direction of the colorbar.
1010
% Note that this function requires that the "mapping toolbox" is installed.
@@ -21,7 +21,7 @@ function geoplotFS(Y,score,ShapeFile)
2121
% computations.
2222
% Data Types - single|double
2323
%
24-
% score : variable to show or nxp matrix containing variables
24+
% score : variable to show or nxp matrix containing variables
2525
% to show.
2626
% Numeric scalar, of string or character identifying the
2727
% initial variable to use in the geoplot. Alternatively,
@@ -30,7 +30,7 @@ function geoplotFS(Y,score,ShapeFile)
3030
% Example - 'ShapeFile','shapefileName'
3131
% Data Types - char or string numeric scalar or nxp array.
3232
%
33-
% ShapeFile : name of ShapeFile or geotable containg shapes.
33+
% ShapeFile : name of ShapeFile or geotable containing shapes.
3434
% Character or string or geotable.
3535
% Name of the ShapeFile containing the containing the
3636
% geometric details of the rows. The ShapeFile, which is
@@ -40,11 +40,16 @@ function geoplotFS(Y,score,ShapeFile)
4040
% "Mapping toolbox" is installed.
4141
% Example - 'ShapeFile','shapefileName'
4242
% Data Types - char or string or geotable.
43-
%
43+
%
4444
% Optional input arguments:
4545
%
46-
% Output:
47-
%
46+
% bsb : list of units forming the initial subset. Vector. If bsb is
47+
% not specified all unis are considered
48+
% Example - 'bsb',1:20
49+
% Data Types - single|double
50+
%
51+
% Output:
52+
%
4853
%
4954
%
5055
% See also: biplotFS
@@ -105,7 +110,59 @@ function geoplotFS(Y,score,ShapeFile)
105110
geoplotFS(X,out.score,ShapeFile)
106111
%}
107112

113+
%{
114+
%% Example of use of option bsb.
115+
load citiesItaly2024.mat
116+
X=citiesItaly2024;
117+
out=pcaFS(X,'biplot',0,'dispresults',0,'plots',0);
118+
ShapeFile=X.Properties.UserData{1};
119+
% Color based on PCs and use of option bsb
120+
% Select the provinces of Emilia-Romagna
121+
bsb=[33:40 99];
122+
geoplotFS(X,out.score,ShapeFile,'bsb',bsb)
123+
%}
124+
125+
108126
%% Beginning of code
109-
geoplotAPP(Y,score,ShapeFile)
127+
bsb=1:size(Y,1);
128+
129+
if nargin>3
130+
options=struct('bsb',bsb);
131+
132+
133+
[varargin{:}] = convertStringsToChars(varargin{:});
134+
UserOptions=varargin(1:2:length(varargin));
135+
if ~isempty(UserOptions)
136+
137+
138+
% Check if number of supplied options is valid
139+
if length(varargin) ~= 2*length(UserOptions)
140+
error('FSDA:geoplotFS:WrongInputOpt','Number of supplied options is invalid. Probably values for some parameters are missing.');
141+
end
142+
143+
% Check if all the specified optional arguments were present
144+
% in structure options
145+
% Remark: the nocheck option has already been dealt by routine
146+
% chkinputR
147+
inpchk=isfield(options,UserOptions);
148+
WrongOptions=UserOptions(inpchk==0);
149+
if ~isempty(WrongOptions)
150+
disp(strcat('Non existent user option found->', char(WrongOptions{:})))
151+
error('FSDA:geoplotFS:NonExistInputOpt','In total %d non-existent user options found.', length(WrongOptions));
152+
end
153+
end
154+
155+
156+
% Write in structure 'options' the options chosen by the user
157+
for i=1:2:length(varargin)
158+
options.(varargin{i})=varargin{i+1};
159+
end
160+
161+
bsb=options.bsb;
162+
163+
end
164+
165+
geoplotAPP(Y,score,ShapeFile,bsb)
166+
110167
end
111168
%FScategory:VIS-Mult

0 commit comments

Comments
 (0)