library(tidyverse)
library(scales)Halving CO2 emissions
Introduction
Visitors to Gapminder.org are welcomed with a question about common misconceptions. Here is one of them.

Once you make your selection, you are directed to a page that explains the right answer and shows a visualization of the distribution of responses from various countries.

Our goal is to create a version of this visualization.
Packages
We will use the tidyverse and scales packages for data wrangling and visualization.
Data
The data we’re going to use is in a CSV file called co2-emissions.csv at https://data-science-with-r.github.io/data/co2-emissions.csv.
co2_emissions <- read_csv("https://data-science-with-r.github.io/data/co2-emissions.csv")Rows: 8 Columns: 4
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (1): country
dbl (3): Very wrong, Wrong, Correct
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
And let’s take a look at the data.
co2_emissions# A tibble: 8 × 4
country `Very wrong` Wrong Correct
<chr> <dbl> <dbl> <dbl>
1 Türkiye 61 23 16
2 Columbia 64 16 20
3 Sweden 36 35 29
4 Germany 26 41 33
5 United Kingdom 29 37 34
6 United States 31 32 37
7 Kenya 46 8 46
8 Pakistan 37 13 50
Analysis
- Pivot the
co2_emissionsdata frame longer such that each row represents a country / answer type combination andanswer_typeandpercentagefor that country are columns in the data frame.
# add code here- Create a stacked bar plot of response type by countries.
# add code here- In the original plot, the levels of
answer_typeare in the order Very wrong, Wrong, and Correct. Update the previous plot reorder the levels in this order.
# add code here- Update the colors of the plot to match the original plot:
- Very wrong: #96283A
- Wrong: #DB4C67
- Correct: #C8F0BF
# add code here- Move the legend to the bottom and make sure the levels appear in the same order they appear in the plot.
# add code here- Reorder countries to match the original plot – in increasing order of corect percentages.
# add code here- Update labels and other elements of the plot to get it closer to the original plot.
# add code here