Trying to make a barchart, but not sure what I am doing wrong. I attached my code and the example,
Please advise.
Trying to make a barchart, but not sure what I am doing wrong. I attached my code and the example,
Please advise.
Hi Jon,
It seems your main problem is with getting the data. Here is one way
greenhouseGases = EntityClass["Chemical", "GreenhouseGases"] // EntityList
euCountries = EntityClass["Country", "EU"] // EntityList
Helper function to get emissions for a country
emissionsFor[country_, gases_] :=
AssociationMap[
country[EntityProperty["Country",
"GreenhouseGasEmissions", {"GreenhouseGas" -> CanonicalName@#}]] &, gases] //
DeleteMissing
e.g. for Austria
emissionsFor[Entity["Country", "Austria"], greenhouseGases]
(*
<|Entity["Chemical", "Methane"] ->
Quantity[7.05709*10^6, IndependentUnit["metric tons of carbon dioxide equivalent"]/("Years")],
Entity["Chemical", "CarbonDioxide"] ->
Quantity[7.96504*10^7, IndependentUnit["metric tons of carbon dioxide equivalent"]/("Years")],
Entity["Chemical", "NitrousOxide"] ->
Quantity[5.25581*10^6, IndependentUnit["metric tons of carbon dioxide equivalent"]/("Years")]|>
*)
Emissions for all countries
AssociationMap[emissionsFor[#, greenhouseGases] &, euCountries]
You should be able to generate the BarChart from this data.
You asked a related question yesterday but it was deleted before I could answer.
greenhouseGases = EntityClass["Chemical", "GreenhouseGases"] // EntityList
countries = {Entity["Country", "France"],
Entity["Country", "Germany"],
Entity["Country", "Italy"],
Entity["Country", "Poland"],
Entity["Country", "Spain"],
Entity["Country", "Sweden"]}
emissionsFor[country_, gases_] := AssociationMap[
country[EntityProperty["Country", "GreenhouseGasEmissions",
{"GreenhouseGas" -> CanonicalName@#}]] &, gases] //
DeleteMissing
data = AssociationMap[emissionsFor[#, greenhouseGases] &, countries]
data // BarChart[#,
ChartLabels -> {CanonicalName@Keys@#, None},
ChartLegends -> CanonicalName@DeleteDuplicates@Keys@Values@#,
PlotTheme -> "Detailed",
FrameLabel -> {"Country", "Metric tons of carbon dioxide equivalent / Year"},
ImageSize -> 500] &