Here is some code for what I want to do:
(* import map and display components *)
image = Import["http://www.theodora.com/maps/new6/african_color.gif"];
image2 = Binarize[image, 0.5];
morphcomp =
MorphologicalComponents[image2 , 0, CornerNeighbors -> False] ;
Colorize[morphcomp]
This loads a map of Africa colour the different components. The code below lets you "zoom in on one of the regions"
(* calculate rows and columns, and number of regios *)
rows = Dimensions[morphcomp][[1]]
columns = Dimensions[morphcomp][[2]]
regions = Length@Tally@Flatten@morphcomp
(* Zoom in on particular region *)
Manipulate[
minrow =
Min[Flatten[
Position[
MemberQ[morphcomp[[#, All]], i] == True & /@ Range[rows], True]]];
maxrow =
Max[Flatten[
Position[
MemberQ[morphcomp[[#, All]], i] == True & /@ Range[rows], True]]];
mincol =
Min[Flatten[
Position[
MemberQ[morphcomp[[All, #]], i] == True & /@ Range[columns],
True]]];
maxcol =
Max[Flatten[
Position[
MemberQ[morphcomp[[All, #]], i] == True & /@ Range[columns],
True]]];
subset = morphcomp[[minrow ;; maxrow, mincol ;; maxcol]];
MatrixPlot[subset], {i, 1, regions, 1}]
Now what I want to do is to do a scatter plot within each region: For example here is a scatter plot (e.g. could be spatial map of individuals voting in the particular country, colored blue/red according to the vote):
(* create density plot *)
blue = 0.75 ;(* 75 percent *)
red = 0.25;
area=100;
chartsize = 1;
numberpoints = 100;
bluepositions =
RandomReal[
area, {numberpoints*blue, 2}]; (*xy coordinates of blue points *)
redpositions =
RandomReal[
area, {numberpoints*red, 2}];(*xy coordinates of red points *)
ListPlot[{bluepositions, redpositions}, PlotStyle -> {Blue, Red}]
To Summarize, what I would like to do is basically is:
- Select a region (say a country within Africa)
- For this country create a scatter plot in the shape of the country (i.e. select random points within the country and color it blue or red - you can assume 75% of ppl voted blue, and 25% red).
- Take this scatterplot (which is shaped like the country) and superimpose it on to the country
- Do this (steps 1-3) for all the regions (which is the number of morphological components) - and then assemble the final image.
- This will look like Africa - where each country within - is overlaid with it's own scatterplot - which shows how in each country, how individuals voted.
This way I can preserve the population densities in the map.
I hope someone can give me some pointers on how this can be done! Maybe it can't be done in Mathematica?
Many thanks,
Priyan.