Categorizing a geographical axis with different colors
    3 views (last 30 days)
  
       Show older comments
    
Hi, I'm trying to plot a geographical axis and categorize it in different colors. The data I have so far is the longtide and latitude of the past 12 months that have occurred in Houston, TX. I want to categorize it by most likely to get flooded and less likely. For example, I want to change the color of the floods closer to each other to red for "severe" change of flooding, and the areas where less floods occur to yellow, then moderate to orange... and so on. 
%graphing a geographical axis
            data = readmatrix("NAEdata.xlsx"); %importing excel data, 
            %column 1 = latitude
            %column 2 = longitude
            xval = data(:,1); 
            yval = data(:,2);
            %making matrix with color data
            colordata = {}; %not a vector, a category (co,plex data type) 
            sizedata = ones(1,length(xval)); %placeholder for ones (want all dots to be of size 1) 
            for i = 1:length(xval)
                numwithindistance = 0;
                for j = 1:length(xval)
                    delx = xval(i)-xval(j); %change in x
                    dely = yval(i)-yval(j); %change in y
                    deltot = (delx^2+dely^2)^(1/2); %total change in lat and lon
                    deltot = deltot * 69; %every change in lat and lon will be every 69 miles
                    if deltot <= 0.5 && deltot ~= 0
                        numwithindistance = numwithindistance + 1; %keeping track of counter 
                    end
                end
                if numwithindistance >= 5
                    colordata.addcats(colordata,{"r"}); %setting the color to red 
                else 
                    colordata.addcats(colordata,{"b"}); %setting the color to blue
                end 
                end
                gb = geobubble(app.UIFigure,xval,yval,sizedata,colordata); %plotting data
               %categorizing the data by color (red=severe), initially none of the data is categorized
0 Comments
Answers (1)
  AKennedy
      
 on 27 Nov 2023
        Hi Natalie,
As I understand, you would like to categorize and plot the geographical data based on the likelihood of flooding. There are a few modifications needed in your code to achieve the desired colour categorization. Here is an updated version of your code:
% Importing data
data = readmatrix("NAEdata.xlsx"); % Importing excel data
xval = data(:,1); % Latitude
yval = data(:,2); % Longitude
% Categorizing the data by color
colordata = cell(length(xval), 1); % Preallocate cell array
sizedata = ones(length(xval), 1); % Set all points to size 1
for i = 1:length(xval)
    numwithindistance = 0;
    for j = 1:length(xval)
        if i ~= j % Avoid comparing the same point
            delx = xval(i) - xval(j); % Change in latitude
            dely = yval(i) - yval(j); % Change in longitude
            deltot = hypot(delx, dely) * 69; % Total change in miles
            if deltot <= 10 % Adjust this distance threshold based on your flooding likelihood criteria
                numwithindistance = numwithindistance + 1;
            end
        end
    end
    % Categorize based on the number of nearby points
    if numwithindistance >= 5
        colordata{i} = 'Severe'; % Categorical value for severe flooding
    elseif numwithindistance >= 3
        colordata{i} = 'Moderate'; % Categorical value for moderate flooding
    else
        colordata{i} = 'Less'; % Categorical value for less flooding
    end
end
colordata = categorical(colordata, {'Less', 'Moderate', 'Severe'}); % Convert to categorical
% Plotting the data
figure
geobubble(xval, yval, sizedata, colordata); 
Here, the code has been modified to convert the colour data to a categorical type using the categorical function, specifying the categories as 'Less', 'Moderate', and 'Severe'. 
The ‘geobubble’ function has been used with the categorized colour data. This should allow you to plot the geographical data with the desired colour categorization. I have also attached a link to the documentation on the ‘geobubble’ function. 
Hope this helps!
0 Comments
See Also
Categories
				Find more on Geographic Plots in Help Center and File Exchange
			
	Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
