# data[].attributes.headline
Allows viewing reports/graphs and download of file with analysis code

# data[].attributes.subject
Allows viewing reports/graphs and download of file with analysis code

# data[].attributes.body
For expert and non-expert audience

# data[].attributes.body
The notebook contains the analysis code behind the dashboard with the state of the dashboard at export time. Below we see how the bargarph can be created. From here, one can perform more advanced analysis which then can be displayed in a  'pretty' format of the notebook (html, pdf, word, ...). This makes the analysis reproducible also.

# data[].attributes.body
For a wider audience

# data[].attributes.body
The blog with the example. Click to view.

# data[].attributes.attachment_link.readable_text
Assume that you have some new data that you want to explore. The new CRAN
version of the 'ExPanDaR' package helps by providing a (customized) R notebook
containing all building blocks of an exploratory data analysis with a few
clicks.

Install the Package and Start ExPanD

First, you need to install the package. I recommend installing the Github
development version of the package as it fixes some small bugs that I
discovered directly after submitting to CRAN (sigh...).

# Install the current development version devtools::install_github("joachim-gassen/ExPanDaR") # Install from CRAN # install.packages("ExPanDaR")

Next, you start ExPanD(), the shiny app of the package that is designed for
interactive data exploration. When you start ExPanD with the parameter
export_nb_option = TRUE, it allows you to export an R notebook containing
the current state of your analysis from within the ExPanD app.

To explore country-level CO2 emissions we will use the World Bank data that
comes with the package but you can do the same with just about every data frame
that contains at least two numerical variables by simply calling
ExPanD(data_frame, export_nb_option = TRUE).

library(ExPanDaR) ExPanD(worldbank, df_def = worldbank_data_def, var_def = worldbank_var_def, export_nb_option = TRUE)

Explore Your Data Interactively

After a little bit of a wait, you will see a shiny app that lets you explore
a country-year panel of World Bank data. Select some visuals to display the
distribution of CO2 emissions, measured in metric tons per inhabitant
( cO2_emissions_capita). You will see that the distribution is log-normal: Many
countries have relatively low levels of emissions while few countries have very
high levels. You can define a logged variant of cO2_emissions_capita in the
app to see that this variable is more normally distributed.

Let's assume that at some point, you are done interactively exploring the data
and want to export your findings for future study. One thing that you can do is
that you can save your current app choices (scroll down, hit save). For the
lazy: The code below reads my choices and starts ExPanD with them so that you
can follow the analysis below (the even lazier can also just access the shiny
app online here).

Export a Notebook Containing Your Analysis

While this allows you to restart ExPanD with your current analysis at a later
point, you most likely want to extend the analysis by hand, e.g. by estimating
more refined models or by adding more visuals. For this, you can export a
Notebook containing the analysis. To do so, scroll to the bottom of the ExPanD
app and click on the button below.

You should be rewarded with a file download dialog, asking you to store a file
named ExPanD_nb.zip. Store and unzip it wherever you like. It contains two
files

A notebook file ExPanD_nb_code.Rmd and

a data file ExPanD_nb_data.RData containing data and variable definitions.

Exploring the Notebook Code

Use RStudio to open the notebook file. You can directly knit it
( Preview/Knit to HTML) but in order to work with and extend it, it is useful
to take a deeper look at its code first. The new vignette
of the package contains more detailed information on the Notebook code. In this
blog post, I will focus on an example for how to extend the analysis.

When you scroll down the notebook, you will see the chunk that creates the
scatter plot. In my analysis, I used it to document that the log of CO2
emissions per capita is almost perfectly proportional to the log of GDP per
capita. See below:

You see that the code of the chunk uses prepare_scatter_plot() of the
'ExPanDaR' package to quickly produce a scatter plot visualizing up to four data
dimensions. See the help pages of the package and the vignette "Using the
functions of the ExPanDaR package"
for more information on how to use the EDA functions that come with the package.
Also, you can always take a look at their code (just call their name without the
brackets) to see what they do under the hood and to extend or modify them.

Modifying and Extending the Notebook

The finding above makes intuitive sense. Economic activity uses resources. Thus,
we would expect countries with higher levels of economic activity to generate
higher levels of CO2 emissions. As you can see above, the analysis is based on
observations from 2014. Based on our argument above, the relation should also
hold over longer periods. Let's see how it looks like when we look at 1980. To
do so, just copy and paste the chunk above and change the sample screen to be
"1980".

Seems to be the case. How does it look when we use all data (just remove the
screen)?

Looking at the whole data frame, the trajectories of the individual countries
become apparent. The big red caterpillar to the left is China, the purple one
below that is India and the Blue blob in the upper right is the U.S. This calls
for a niced-up "Hans-Rosling-style" animation. Let's do this.

library(gganimate) iso3c % select(iso3c, country) %>% distinct() df % left_join(iso3c, by = "country") df % filter(year <= 2014) %>% group_by(country) %>% mutate(nobs = n()) %>% ungroup() %>% filter(nobs == max(nobs)) df$region 50), aes(label = iso3c), nudge_x = 0.1, nudge_y = 0.1, size = 2) + transition_time(year) + ease_aes('linear') animate(aplot, start_pause = 20, end_pause = 20)

You see that most of the countries are moving to the upper right over time. This
is good (higher economic productivity) and bad (higher CO2 emissions per capita)
at the same time. Only very few European countries seem to be moving slightly
downwards in later years, indicating reducing CO2 emissions per capita.
It is a pity that the CO2 data provided by the World Bank currently stops in 2014.

Anyhow, you see that a notebook generated with a few clicks based on the interactive
ExPanD analysis can serve as a starting point for a more in-depth analysis.
Now it is your turn. Feel free to modify and extend your analysis along all
possible dimensions. Code away and enjoy!

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

# data[].attributes.attachment_link.authors[].name
An Accounting and Data Science Nerd's Corner

# data[].attributes.attachment_link.title
Create a Notebook to Explore Country-Level CO2 Emissions With a Few Clicks

# data[].attributes.attachment_link.description
Assume that you have some new data that you want to explore. The new CRAN version of the 'ExPanDaR' package helps by providing a (customized) R notebook containing all building blocks of an exploratory data analysis with a few clicks. Install the Package and Start ExPanD First, you need to install the package.

# data[].attributes.body
The data get loaded into a dashboard which can be controlled with filters etc (on the left). The dashboard is a Shiny R application that can run on a local machine or be hosted on the web.  The data are directly imported from the Worldbank on nations' CO2 emissions