Gapminder data package import

library(gapminder)
data(gapminder)
library(ggplot2)
p = ggplot(data=gapminder, aes(x=gdpPercap, y=lifeExp))
p = p + geom_point()
p

p = p + geom_line()
p

p = ggplot(data=gapminder, aes(x=gdpPercap, y=lifeExp, color=continent))
p = p + geom_point()
p

p = p + geom_smooth(method="loess")
p
## `geom_smooth()` using formula 'y ~ x'

p = p + scale_x_log10()
p
## `geom_smooth()` using formula 'y ~ x'

p = ggplot(data = gapminder, aes(x = gdpPercap, y = lifeExp))
p = p + geom_point(aes(color=continent))
p = p + geom_smooth(method="loess") + scale_x_log10()
p = p + labs(x="Log GDP per Capita", y="Life Expectancy")
p
## `geom_smooth()` using formula 'y ~ x'

p = p + ggtitle("Association between GDP Per Capita and Life Expectancy") + theme(plot.title=element_text(lineheight=0.8, face="bold", hjust = 0.5))
p
## `geom_smooth()` using formula 'y ~ x'

library(ggthemes)
p + theme_economist()
## `geom_smooth()` using formula 'y ~ x'

labs(title="Association between GDP Per Capita and Life Expectancy", x="Log GDP per Capita", y="Life Expectancy")
## $x
## [1] "Log GDP per Capita"
## 
## $y
## [1] "Life Expectancy"
## 
## $title
## [1] "Association between GDP Per Capita and Life Expectancy"
## 
## attr(,"class")
## [1] "labels"
p
## `geom_smooth()` using formula 'y ~ x'

theme(axis.title.x=element_text(color="blue", size=10, face="bold"),
axis.text.x=element_text(angle=45, vjust=0.5, size=10, face="bold"),
axis.title.y = element_text(color="blue", size=14, face="bold"),
axis.text.y=element_text(angle=90, vjust=0.5, size=10, face="bold"))
## List of 4
##  $ axis.title.x:List of 11
##   ..$ family       : NULL
##   ..$ face         : chr "bold"
##   ..$ colour       : chr "blue"
##   ..$ size         : num 10
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi FALSE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.title.y:List of 11
##   ..$ family       : NULL
##   ..$ face         : chr "bold"
##   ..$ colour       : chr "blue"
##   ..$ size         : num 14
##   ..$ hjust        : NULL
##   ..$ vjust        : NULL
##   ..$ angle        : NULL
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi FALSE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.x :List of 11
##   ..$ family       : NULL
##   ..$ face         : chr "bold"
##   ..$ colour       : NULL
##   ..$ size         : num 10
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0.5
##   ..$ angle        : num 45
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi FALSE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  $ axis.text.y :List of 11
##   ..$ family       : NULL
##   ..$ face         : chr "bold"
##   ..$ colour       : NULL
##   ..$ size         : num 10
##   ..$ hjust        : NULL
##   ..$ vjust        : num 0.5
##   ..$ angle        : num 90
##   ..$ lineheight   : NULL
##   ..$ margin       : NULL
##   ..$ debug        : NULL
##   ..$ inherit.blank: logi FALSE
##   ..- attr(*, "class")= chr [1:2] "element_text" "element"
##  - attr(*, "class")= chr [1:2] "theme" "gg"
##  - attr(*, "complete")= logi FALSE
##  - attr(*, "validate")= logi TRUE
p
## `geom_smooth()` using formula 'y ~ x'

p = p + scale_x_continuous(breaks=seq(0, 90000, 30000)) + scale_y_continuous(breaks=seq(0, 100, 20))
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
p
## `geom_smooth()` using formula 'y ~ x'

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.