library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.6 v dplyr 1.0.7
## v tidyr 1.1.4 v stringr 1.4.0
## v readr 2.1.0 v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
gapminder <- read_csv("gapminder.csv")
## Rows: 1560 Columns: 7
## -- Column specification --------------------------------------------------------
## Delimiter: ","
## chr (3): country, continent, region
## dbl (4): year, lifeExp, pop, gdpPercap
##
## i Use `spec()` to retrieve the full column specification for this data.
## i Specify the column types or set `show_col_types = FALSE` to quiet this message.
theme_scatter <- theme(
plot.title = element_text(size = 14, vjust = 0, hjust = 0),
plot.caption = element_text(size = 10, color = "#6d6d6d"),
axis.title.x = element_text(size = 12, hjust = 0.95, vjust = 1.5, color = "#6d6d6d"),
axis.title.y = element_text(size = 12, hjust = 0.95, vjust = 1.5, color = "#6d6d6d"),
axis.text.x = element_text(size = 12, color = "#6d6d6d"),
axis.text.y = element_text(size = 12, color = "#6d6d6d"),
axis.line.x= element_line(color="#a9a9a9", size = 0.75),
axis.line.y= element_line(color="#a9a9a9", size = 0.75),
axis.ticks.y = element_line(color="#a9a9a9", size = 0.75),
axis.ticks.x = element_line(color="#a9a9a9", size = 0.75),
# legend.position = "none",
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank(),
legend.title=element_blank(),
plot.margin = margin(1, 1, 0.5, 1, "cm")) # margin(t = 0, r = 0, b = 0, l = 0, unit = "pt")
ggplot(data = gapminder %>%
filter(year == 2007),
aes(x= gdpPercap, y = lifeExp)) +
geom_point() +
labs(x = 'GDP per Capita',
y = 'Life Expectency (Year)',
title = "Relationship using scatter plot \n\n",
caption = "source: gapminder pacakge") +
theme_scatter

ggplot(data = gapminder %>%
filter(year == 2007),
aes(x= gdpPercap, y = lifeExp)) +
geom_point(aes(colour = continent, size = 3, alpha = 0.1)) +
guides(size = FALSE, alpha = FALSE) +
labs(x = 'GDP per Capita',
y = 'Life Expectency (year)',
title = "Relationship using scatter plot \n\n",
caption = "source: gapminder pacakge") +
theme_scatter
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.

ggplot(data = gapminder %>%
filter(year == 2007 & country != "China" & country != "India"),
aes(x= pop, y = lifeExp)) +
geom_point(aes(colour = continent, size = 3, alpha = 0.1 )) +
guides(size = FALSE, alpha = FALSE) +
labs(x = 'Population',
y = 'Life Expectency (Year)',
title = "Relationship between life expectancy and population\n\n",
caption = "source: gapminder pacakge") +
theme_scatter
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.

ggplot(data = gapminder %>%
filter(year == 2007 & country != "China" & country != "India"),
aes(x= pop, y = gdpPercap)) +
geom_point(aes(colour = continent, size = 3, alpha = 0.1 )) +
guides(size = FALSE, alpha = FALSE) +
labs(x = 'Population',
y = 'gdpPercap',
title = "Relationship between life expectancy and population\n\n",
caption = "source: gapminder pacakge") +
theme_scatter
## Warning: `guides(<scale> = FALSE)` is deprecated. Please use `guides(<scale> =
## "none")` instead.
