packageForGapminder
is a package which makes model pop/lifeExp/gdpPercap VS year for countries in gapminder dataset easier, as well as makes it possible to use only one line code to help you get a intuitive view on how well pop/lifeExp/gdpPercap and year in gapminder dataset fits a linear model.
To install the package:
library(packageForGapminder) ## load some other packages here library(knitr) options(knitr.table.format="markdown") #Set the format for tables as "markdown"
In this package, we have three functions in total. See below.
gapminder_lmfit()
: Fit a linear model to pop/lifeExp/gdpPercap VS year for a country in gapminder dataset.
gapminder_lm_table()
: Create a table for fitted linear model between variables pop/lifeExp/gdpPercap and year in gapminder dataset.
gapminder_lm_plot()
:Draw a plot to show how well pop/lifeExp/gdpPercap and year in gapminder dataset fits a linear model.
Besides, by default, all these three funtions will fit the linear model to data pop
VS year
for a gapminder country.
gapminder_lmfit()
:Fit linear model to gapminder country data.
gapminder_lmfit("Canada") ##fit a linear model to pop VS year for "Canada" gapminder_lmfit("Canada","year","lifeExp") ##fit a linear model to lifeExp VS year for "Canada" gapminder_lmfit("China","year","gdpPercap") ##fit a linear model to gdpPercap VS year for "China"
gapminder_lm_table()
:Get the table which compares the actual pop/lifeExp/gdpPercap values with the predicted values that we compute from the linear model.
table1 <- gapminder_lm_table("Canada") kable(table1) table2 <- gapminder_lm_table("Canada","year","lifeExp") kable(table2) table3 <- gapminder_lm_table("China","year","gdpPercap") kable(table3)
gapminder_lm_plot()
:Draw a plot to give you an intuitive view on how well a gapminder country data(pop/lifeExp/gdpPercap VS year) fits a linear model.
gapminder_lm_plot("Canada") gapminder_lm_plot("Canada","year","lifeExp") gapminder_lm_plot("China","year","gdpPercap")
packageForGapminder
really makes it easier to check the linear relationships between pop/lifeExp/gdpPercap
and year
for a gapminder country.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.