This case study taught me some important techniques. It is worth pointing out that ggplot is fast and efficient for data visualization. This is because the creaters of that package allowed graphics to be added by layers. Furthermore, facets are great for making multiple plots that are grouped by a single variable.
There were also some good mistakes that I made that are worth remembering. When adding in variables as aesthetics don’t wrap the variable in quotes. It’s also important to remember that when you use the group() function that it goes in inside the aes() function. Futhermore, the mutate() function adds a new column while summarise() reformats the data table to be the size of the factor you chose.
ggplot(data = plot_data, mapping = aes(x = lifeExp, y = gdpPercap)) +
geom_point(mapping = aes(color = continent, size = pop_100k)) +
facet_wrap(~ year, nrow = 1) +
labs(x = "Life Expectancy", y = "GDP per Capita", size = "Population (100k)", color = "Continent") +
scale_y_continuous(trans = "sqrt") +
theme_bw()
ggplot(data = plot_data, mapping = aes(x = year, y = gdpPercap), position = "jitter") +
geom_point(mapping = aes(color = continent, group = country)) + #Continent Data
geom_line(mapping = aes(color = continent, group = country)) + #Continent Data
geom_point(data = plot_data_cont, mapping = aes(y = weighted_mean_gdp, size = population)) + #Black Line
geom_line(data = plot_data_cont, mapping = aes(y = weighted_mean_gdp)) + #Black Line
facet_wrap(~ continent, nrow = 1) +
labs(x = "Year", y = "GDP per Capita", color = "Continent", size = "Population (100K)") +
scale_y_continuous(trans = "sqrt") +
theme_bw()