Gapminder
library(pacman)
p_load(tidyverse, gapminder)
gapminder
gapminder %>%
ggplot(aes(x = gdpPercap, y = lifeExp )) +
geom_point()
gapminder %>%
ggplot(aes(x = log(gdpPercap), y = log(lifeExp))) +
geom_point()
gapminder %>%
ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) +
geom_point() +
geom_text(aes(label=ifelse(country=="United States",as.character(country),'')),hjust=-0.2,vjust=0)
Faceting
gapminder
gapminder %>%
ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) +
geom_point() +
facet_wrap(~year)
Plot.ly
library(plotly)
p <- gapminder %>%
ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) +
geom_point() +
facet_wrap(~year)
ggplotly(p)
Plot.ly faceting
library(plotly)
p <- gapminder %>%
ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) +
geom_point() +
facet_wrap(~year)
ggplotly(p)
Plot.ly annimation with ggplot.
To learn about Plot.ly R and Plot.ly ggplot.
The plot.ly book is an excellent place to start to learn about use of annimation plot.ly chapter 5.
gg <- gapminder %>% ggplot(aes(log(gdpPercap), log(lifeExp), color = continent)) +
geom_point(aes(size = pop, frame = year, ids = country))
Ignoring unknown aesthetics: frame, ids
ggplotly(gg)
LS0tCnRpdGxlOiAiU3RhdC4gNjUxIFdlbGNvbWUiCmF1dGhvcjogIlByb2YuIEVyaWMgQS4gU3Vlc3MiCmRhdGU6ICIxMC8xMi8yMDIwIgpvdXRwdXQ6CiAgaHRtbF9ub3RlYm9vazogZGVmYXVsdAogIHBkZl9kb2N1bWVudDogZGVmYXVsdAogIHdvcmRfZG9jdW1lbnQ6IGRlZmF1bHQKLS0tCgojIEdhcG1pbmRlcgoKYGBge3J9CmxpYnJhcnkocGFjbWFuKQpwX2xvYWQodGlkeXZlcnNlLCBnYXBtaW5kZXIpCgpnYXBtaW5kZXIKYGBgCgoKYGBge3J9CmdhcG1pbmRlciAlPiUgCiAgZ2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