1
$\begingroup$

I am creating a stacked bar chart from 2017 using the following data set

top2017 = <|"France" -> 147/10640, 
   "Brazil" -> 148/10640, 
   "Germany" -> 293/10640, 
   "Australia" -> 453/10640, 
   "Canada" -> 883/10640, 
   "United Kingdom" -> 1119/10640, 
   "United States of America" -> 6163/10640|>;

and I currently create this bar chart

bar chart

with the following code

BarChart[top2017, ChartLayout -> "Stacked", ChartStyle -> "Rainbow", 
 Epilog -> 
  Inset[Framed[
    PointLegend[
     "Rainbow", {"France", "Brazil", "Germany", "Australia", "Canada",
       "United Kingdom", "USA"}, 
     LegendMarkers -> {Graphics[Rectangle[]]}], RoundingRadius -> 5], 
   Scaled[{0.8, 0.5}]], Frame -> True, ImageSize -> Scaled[0.5], 
 ChartLabels -> {"2017"}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 18}, 
 FrameLabel -> {{"% respondents", ""}, {"Year", "Ace Survey"}}]

and then I also create another bar chart for 2018 using

top2018 = <|{"Italy"} -> 203/15177,
            {"Netherlands"} -> 210/15177,
            {"Australia"} -> 549/15177,
            {"France"} -> 243/15177,
            {"Germany"} -> 689/15177, {"Canada"} -> 1020/15177,
            {"United Kingdom"} -> 1338/15177,
            {"United States of America"} -> 8635/15177|>;
BarChart[top2018, ChartLayout -> "Stacked", 
 ChartStyle -> "Rainbow", 
 Epilog -> 
  Inset[Framed[
    PointLegend[
     "Rainbow", {"Italy", "Netherlands", "Australia", "France", 
      "Germany", "Canada", "United Kingdom", "USA"}, 
     LegendMarkers -> {Graphics[Rectangle[]]}], RoundingRadius -> 5], 
   Scaled[{0.8, 0.5}]], Frame -> True, ImageSize -> Scaled[0.5], 
 ChartLabels -> {"2018"}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 18}, 
 FrameLabel -> {{"% respondents", ""}, {"Year", "Ace Survey"}}]

This gives me a chart that looks pretty similar to the one already included. Initially I was going to continue using "Rainbow" in chart style, but now that I see that I have some different countries in different years, I decided against that. I was initially going to use a set color for specific countries---say, set USA to red, France to blue, Germany to yellow etc etc and use that for every year. But then I was wondering: is there a way to use country flags in chart style? Initially I used

EntityValue[Entity["Country", "USA"], {"Entity", "Flag"}]

To manually produce the flag for each country. Then I just copied the flags produced and pasted them in flags = {}; where each flag image went into flags. When I plot the following I get an error

BarChart[top2017, ChartLayout -> "Stacked", ChartStyle -> flags, 
 Epilog -> 
  Inset[Framed[
    PointLegend[
     "Rainbow", {"France", "Brazil", "Germany", "Australia", "Canada",
       "United Kingdom", "USA"}, 
     LegendMarkers -> {Graphics[Rectangle[]]}], RoundingRadius -> 5], 
   Scaled[{0.8, 0.5}]], Frame -> True, ImageSize -> Scaled[0.5], 
 ChartLabels -> {"2018"}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 18}, 
 FrameLabel -> {{"% respondents", ""}, {"Year", "Ace Survey"}}]

where it says that

Value of option ChartStyle -> {flags} is not a style or group of styles.

tl;dr How would one go about using a flags/flags in chart style for a bar chart?

EDIT: For reference I got the idea to use the flags from here

https://www.wolfram.com/mathematica/new-in-10/entity-based-geocomputation/map-the-countries-of-africa-with-their-flags.html

as well as here

Getting all the countries' flags and then using them as chart labels?

but neither were exactly what I need.

$\endgroup$
2
  • $\begingroup$ Since only you have countries2017 and no one else, why not copy the output of top2017 directly into your post? (Similarly for top2018.) $\endgroup$ Commented Apr 2, 2019 at 0:59
  • $\begingroup$ Hopefully the edit shows what I meant. Since there's no list to get a length from, it would have been better to directly paste the Association[] with the actual numbers. $\endgroup$ Commented Apr 2, 2019 at 1:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.