Animated Gapminder Code(2)
Animated Gapminder Code(2)
2. Coding Environment
Now, fire up your IDE of choice whether it be RStudio,
Kaggle Notebooks or a plain old R terminal. Within this
coding environment you will be typing in the codes
mentioned hereafter.
5.1. Code
From the above screenshot we can see that the plot is shown
in the Plots panel (lower left panel) but is not saved to a file.
To save the plot to a file, we will use the ggsave() function as
follows:
ggsave('plot_gdpPercap_lifeExp_static.png', width=8, height=8)
6.1. Code
Notice that in the above code we’re using pop and lifeExp as
the first and second input arguments (as compared to
using gdpPercap and lifeExp in the first plot).
facet_wrap(~continent, ncol=5).
facet_wrap(~continent, ncol=1).
7.3. Adjusting the font size
You may notice that font sizes for the X/Y axes and tick labels
may be small and you would like to adjust it. Let me show
you how.
You will notice that we have added Lines 7–13 which makes
use of the theme() function to adjust the font sizes, faces and
colors.
Conclusion
Aside from the animated plot for time series data, you can
also experiment with the gganimate R package to spice up
other data visualization and add animation to it such as box
plots