9
$\begingroup$

I am trying to combine two world maps with the command "show" and Mathematica indicates an error (see images underneath). Does anyone know what the problem might be and how I can solve it? I am thankful for any help!

The most important codes:

data = Map[Rule[Entity["Country", #[[1]]], #[[2]]] &, 
  DataACT1Combination$TMP]

H = 
  GeoBubbleChart[data, 
    BubbleSizes -> {0.02, 0.04}, 
    BubbleScale -> "Diameter", 
    ImageSize -> 1000,ColorFunction -> "Rainbow"]




   DevelopedCountries = {Entity["Country", "Albania"], Entity["Country", "Algeria"], Entity["Country", "Argentina"], Entity["Country", "Australia"], Entity["Country", "Austria"], Entity["Country", "Azerbaijan"], Entity["Country", "Bahamas"], Entity["Country", "Bahrain"], Entity["Country", "Barbados"], Entity["Country", "Belarus"], Entity["Country", "Belgium"], Entity["Country", "BosniaHerzegovina"],Entity["Country", "Botswana"], Entity["Country", "Brazil"], Entity["Country", "Brunei"], Entity["Country", "Bulgaria"], Entity["Country", "Canada"], Entity["Country", "Chile"], Entity["Country", "China"], Entity["Country", "Colombia"], Entity["Country", "CostaRica"], Entity["Country", "Croatia"], Entity["Country", "Cuba"], Entity["Country", "Cyprus"], Entity["Country", "CzechRepublic"], Entity["Country", "Denmark"], Entity["Country", "Dominica"], Entity["Country", "DominicanRepublic"],Entity["Country", "Ecuador"], Entity["Country", "Egypt"],Entity["Country", "EquatorialGuinea"], Entity["Country", "Estonia"],Entity["Country", "Finland"], Entity["Country", "France"], Entity["Country", "Gabon"], Entity["Country", "Georgia"], Entity["Country", "Germany"], Entity["Country", "Greece"], Entity["Country", "Hungary"], Entity["Country", "Iceland"], Entity["Country", "Indonesia"], Entity["Country", "Iran"], Entity["Country", "Iraq"], Entity["Country", "Ireland"], Entity["Country", "Israel"], Entity["Country", "Italy"], Entity["Country", "Japan"], Entity["Country", "Jordan"], Entity["Country", "Kazakhstan"], Entity["Country", "SouthKorea"], Entity["Country", "Kuwait"], Entity["Country", "Latvia"], Entity["Country", "Lebanon"], Entity["Country", "Liechtenstein"], Entity["Country", "Lithuania"], Entity["Country", "Luxembourg"], Entity["Country", "Macedonia"], Entity["Country", "Malaysia"], Entity["Country", "Maldives"], Entity["Country", "Malta"], Entity["Country", "Mauritius"], Entity["Country", "Mexico"], Entity["Country", "Mongolia"], Entity["Country", "Montenegro"], Entity["Country", "Namibia"], Entity["Country", "Netherlands"], Entity["Country", "NewZealand"], Entity["Country", "Norway"], Entity["Country", "Oman"], Entity["Country", "Panama"], Entity["Country", "Peru"], Entity["Country", "Poland"], Entity["Country", "Portugal"], Entity["Country", "Qatar"], Entity["Country", "Romania"], Entity["Country", "Russia"], Entity["Country", "SaintLucia"], Entity["Country", "SaintVincentGrenadines"], Entity["Country", "SaudiArabia"], Entity["Country", "Serbia"], Entity["Country", "Seychelles"], Entity["Country", "Singapore"], Entity["Country", "Slovakia"], Entity["Country", "Slovenia"], Entity["Country", "SouthAfrica"], Entity["Country", "SouthSudan"], Entity["Country", "Spain"], Entity["Country", "Sudan"], Entity["Country", "Suriname"], Entity["Country", "Sweden"], Entity["Country", "Syria"], Entity["Country", "Tanzania"], Entity["Country", "TrinidadTobago"], Entity["Country", "Tunisia"], Entity["Country", "Turkey"], Entity["Country", "Turkmenistan"], Entity["Country", "UnitedArabEmirates"], Entity["Country", "UnitedKingdom"], Entity["Country", "UnitedStates"], Entity["Country", "Uruguay"], Entity["Country", "Venezuela"]}




DevelopingCountries = {Entity["Country", "Afghanistan"], Entity["Country", "Angola"], Entity["Country", "Armenia"], Entity["Country", "Benin"], Entity["Country", "Bhutan"], Entity["Country", "Bolivia"], Entity["Country", "BurkinaFaso"], Entity["Country", "Burundi"], Entity["Country", "CapeVerde"], Entity["Country", "Cambodia"], Entity["Country", "Cameroon"], Entity["Country", "CentralAfricanRepublic"], Entity["Country", "Chad"], Entity["Country", "Comoros"], Entity["Country", "DemocraticRepublicCongo"], Entity["Country", "RepublicCongo"], Entity["Country", "IvoryCoast"],Entity["Country", "Djibouti"], Entity["Country", "ElSalvador"], Entity["Country", "Eritrea"], Entity["Country", "Swaziland"], Entity["Country", "Ethiopia"], Entity["Country", "Fiji"], Entity["Country", "Gambia"], Entity["Country", "Ghana"], Entity["Country", "Guatemala"], Entity["Country", "Guinea"], Entity["Country", "GuineaBissau"], Entity["Country", "Guyana"], Entity["Country", "Haiti"], Entity["Country", "Honduras"], Entity["Country", "India"], Entity["Country", "Jamaica"], Entity["Country", "Kenya"], Entity["Country", "Kiribati"], Entity["Country", "Kosovo"], Entity["Country", "Kyrgyzstan"], Entity["Country", "Laos"], Entity["Country", "Lesotho"], Entity["Country", "Liberia"], Entity["Country", "Libya"], Entity["Country", "Madagascar"], Entity["Country", "Malawi"], Entity["Country", "Mali"], Entity["Country", "Mauritania"], Entity["Country", "Micronesia"], Entity["Country", "Moldova"], Entity["Country", "Morocco"], Entity["Country", "Mozambique"], Entity["Country", "Myanmar"], Entity["Country", "Nepal"], Entity["Country", "Nicaragua"], Entity["Country", "Niger"], Entity["Country", "Nigeria"], Entity["Country", "Pakistan"], Entity["Country", "PapuaNewGuinea"], Entity["Country", "Paraguay"], Entity["Country", "Philippines"], Entity["Country", "Rwanda"], Entity["Country", "Samoa"], Entity["Country", "SaoTomePrincipe"], Entity["Country", "Senegal"], Entity["Country", "SierraLeone"], Entity["Country", "SolomonIslands"], Entity["Country", "SriLanka"], Entity["Country", "Taiwan"], Entity["Country", "Tajikistan"], Entity["Country", "EastTimor"], Entity["Country", "Togo"], Entity["Country", "Tonga"], Entity["Country", "Uganda"], Entity["Country", "Ukraine"], Entity["Country", "Uzbekistan"], Entity["Country", "Vanuatu"], Entity["Country", "Vietnam"], Entity["Country", "Yemen"], Entity["Country", "Zambia"], Entity["Country", "Zimbabwe"]}

Color$Developed = Blue
Color$Developing = Red

FinalPlotCountries =
   Labeled[
     GeoRegionValuePlot[
       Join[
         Map[Rule[#, Color$Developed] &, DevelopedCountries], 
         Map[Rule[#, Color$Developing] &, DevelopingCountries]], 
       GeoLabels -> False, 
       LabelStyle -> {8, Bold, Italic}, 
       ImageSize -> 1000, 
       GeoRange -> "World", 
       AspectRatio -> 1/1.5, 
       Epilog -> 
         Inset[
           SwatchLegend[
             {Blue, Red}, {"developed    ",  "developing    "}, 
             LegendLayout -> "Row"],
           Scaled[{0.5, 0.03}]]] // Framed, 
     Style["Development Status of Countries", 25, FontFamily -> "Times"],
     Top]

Show [FinalPlotCountries, H]

Map1 Map2

Error message

$\endgroup$
  • 1
    $\begingroup$ Sorry, I am new here! Posted the codes above now $\endgroup$ – Faye Drew Jan 2 at 15:21
  • $\begingroup$ You are setting GeoBubbleChart to GeoBubbleChart, use a different name. Can you provide data so we can reproduce your result. What is DevelopedCountries and Color$Developed and Color$Developing? $\endgroup$ – Rohit Namjoshi Jan 2 at 15:42
  • $\begingroup$ data, Color$Developed and DevelopedCountries are not defined in your code, so it doesn't evaluate properly and we can't see what your problem is. Also, in your 1st chart, a comma is missing after ImageSize -> 100 $\endgroup$ – m_goldberg Jan 2 at 15:47
  • $\begingroup$ Thank you for the answers! As I am working on a large dataset it is hard for me to include every code used. But I added data, (wich is a combination ( DataACT1Combination$TMP) of the world happiness score (provided in the dataset) and a list of the countries, also provided in the dataset), Color$Developed, Color$Developing, DevelopingCountries and DevelopedCountries $\endgroup$ – Faye Drew Jan 2 at 16:15
12
$\begingroup$
SeedRandom[1]
fiftycountries = RandomSample[EntityList["Country"], 50];
selected = RandomSample[fiftycountries, 30];
data = # -> #[ "Population"] & /@ selected;
others = Complement[fiftycountries, selected];

Easiest way to show the two plots together is to use the graphics primitives produced by GeoBubbleChart as Epilog in GeoRegionValuePlot:

gbc = GeoBubbleChart[data, BubbleSizes -> {0.02, 0.04}, 
   BubbleScale -> "Diameter", 
   ColorFunction -> "Rainbow", GeoRange -> "World", 
   GeoBackground -> None];


fpc = Labeled[GeoRegionValuePlot[
    Join[Map[Rule[#, Opacity[.5, Red]] &, selected], 
     Map[Rule[#, Blue] &, others]], GeoLabels -> False, 
    LabelStyle -> {8, Bold, Italic}, ImageSize -> 900, 
    GeoRange -> "World", 
    Epilog -> {gbc[[1, 1]], 
      Inset[SwatchLegend[{Red, Blue}, {"selected    ", "others    "}, 
        LegendLayout -> "Row"], Scaled[{0.5, 0.03}]]}] // Framed, 
  Style["Development Status of Countries", 25, FontFamily -> "Times"], Top]

enter image description here

Alternatively, you can use Show using the GeoGraphics object in your FinalPlotCountries (which is the part FinalPlotCountries[[1,1]]) add Framed and Labeled later:

Labeled[Framed@Show[FinalPlotCountries[[1, 1]], gbc], 
 Style["Development Status of Countries", 25, FontFamily -> "Times"], Top]

enter image description here

but this approach requires further work to clean up white paddings.

Why your code does not work?

Show expects objects with head Graphics (or GeoGraphics) as arguments. fpc is an object with Head Labeled (not GeoGraphics).

A simpler example that shows the same issue:

plot1 = Plot[Sin[x], {x, 0, 2 Pi}, PlotStyle -> Red];
plot2 = Labeled[Framed@Plot[Cos[x], {x, 0, 2 Pi}, PlotStyle -> Blue], 
   Style["label", 20], Top];
Show[plot2, plot1]

enter image description here

The fix is the same: Either use the graphics primitives of plot1 (i.e., plot1[[1]]) as Epilog in the second plot:

Labeled[Framed@
  Plot[Cos[x], {x, 0, 2 Pi}, PlotStyle -> Blue, 
   Epilog -> plot1[[1]]], Style["label", 20], Top]

or use Show[plot2[[1, 1]], plot1] and add the frame and labels later:

Labeled[Framed @ Show[plot2[[1, 1]], plot1], Style["label", 20], Top]

Both approaches give

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you so much! It worked! Do you also happen to know how to add a second legend to the right of the map fpc that shows each bubble size and respective color (from the map) with the respective number and the legend title "Happiness scores"? I can unfortunately not manage $\endgroup$ – Faye Drew Jan 2 at 20:45
  • $\begingroup$ @Faye, normally, if plot1 and plot2 are produced with the PlotLegends (or ChartLegends) option Show[plot1,plot2] combines the legends of the two plots. But with the combination of GeoBubbleChart (with the option ChartLegends ) and GeoRegionValuePlot` (with the option PlotLegends), obvious things i tried did not work. You might want to post this as a new question with a simplified example. $\endgroup$ – kglr Jan 2 at 23:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.