Superstore sample dataset that is shipped with Tableau
# download data
library(tidyverse)
## ── Attaching packages ──────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.3.0
## ✔ tibble 2.0.1 ✔ dplyr 0.8.0.1
## ✔ tidyr 0.8.2 ✔ stringr 1.4.0
## ✔ readr 1.3.1 ✔ forcats 0.4.0
## ── Conflicts ─────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(lubridate)
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
download.file("https://raw.githubusercontent.com/mikemooreviz/superstore/master/superstore.csv", "superstore.csv")
superstore <- read.csv("superstore.csv", header = TRUE)
superstore$Order.Date <- as.Date(superstore$Order.Date)
head(superstore)
Grouping and aggreating data to visualize
store <- superstore %>%
mutate(Year = year(as.Date(Order.Date))) %>%
filter(State %in% c('Ohio', 'Indiana', 'Kentucky')) %>%
select(Year, State, Sales) %>%
group_by(Year, State) %>%
summarise(Total_Sales = sum(Sales))
head(store)
theme_set(theme_gray())
plot <- ggplot(store, aes(x = Year, y = Total_Sales, fill = State, color = State))
plot
plot + geom_col() +
theme_gray()
plot + geom_line() +
geom_point() +
theme_gray()
# ggplot 2 default themes
# https://ggplot2.tidyverse.org/reference/ggtheme.html
# theme_bw()
plot + geom_col()+
theme_bw()
plot + geom_line() +
geom_point() +
theme_bw()
# theme_minimal()
plot + geom_col() +
theme_minimal()
plot + geom_line() +
geom_point() +
theme_minimal()
# theme_dark()
plot + geom_col() +
theme_dark()
plot + geom_line() +
geom_point() +
theme_dark()
https://github.com/jrnold/ggthemes
# theme_wsj()
library(ggthemes)
plot + geom_col() +
theme_wsj() +
scale_fill_manual(values = wsj_pal(palette = "colors6")(3)) +
scale_color_manual(values = wsj_pal(palette = "colors6")(3))
plot + geom_line() +
geom_point() +
theme_wsj() +
scale_color_manual(values = wsj_pal(palette = "colors6")(3))
library(scales)
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
plot + geom_col() +
theme_economist() +
scale_fill_manual(values = economist_pal(fill = TRUE)(3)) +
scale_color_manual(values = economist_pal(fill = TRUE)(3))
plot + geom_line() +
geom_point() +
theme_economist() +
scale_color_manual(values = economist_pal(fill = TRUE)(3))
plot + geom_col() +
theme_fivethirtyeight() +
scale_fill_manual(values = fivethirtyeight_pal()(3)) +
scale_color_manual(values = fivethirtyeight_pal()(3))
plot + geom_line() +
geom_point() +
theme_fivethirtyeight() +
scale_color_manual(values = fivethirtyeight_pal()(3))
plot + geom_col() +
theme_tufte() +
scale_fill_manual(values = colorblind_pal()(3)) +
scale_color_manual(values = colorblind_pal()(3))
plot + geom_line() +
geom_point() +
theme_tufte() +
scale_color_manual(values = colorblind_pal()(3))
plot + geom_col() +
theme_few() +
scale_fill_manual(values = few_pal()(3)) +
scale_color_manual(values = few_pal()(3))
plot + geom_line() +
geom_point() +
theme_few() +
scale_color_manual(values = few_pal()(3))
https://github.com/hrbrmstr/hrbrthemes
# hrbrthemes
library(hrbrthemes)
## NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.
## Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and
## if Arial Narrow is not on your system, please see http://bit.ly/arialnarrow
plot + geom_col() +
theme_ft_rc()
plot + geom_line() +
geom_point() +
theme_ft_rc()
plot + geom_col() +
theme_ipsum_ps() +
scale_fill_ipsum(3) +
scale_color_ipsum(3)
plot + geom_line() +
geom_point() +
theme_ipsum_ps() +
scale_color_ipsum(3)
https://github.com/kassambara/ggpubr
# ggpubr()
# https://rpkgs.datanovia.com/ggpubr/reference/theme_pubr.html
library(ggpubr)
## Loading required package: magrittr
##
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
##
## set_names
## The following object is masked from 'package:tidyr':
##
## extract
plot + geom_col() +
theme_pubr() +
scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07")) +
scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
plot + geom_line() +
geom_point() +
theme_pubr() +
scale_color_manual(values = c("#00AFBB", "#E7B800", "#FC4E07"))
https://github.com/business-science/tidyquant
# tidyquant
library(tidyquant)
## Loading required package: PerformanceAnalytics
## Loading required package: xts
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'xts'
## The following objects are masked from 'package:dplyr':
##
## first, last
##
## Attaching package: 'PerformanceAnalytics'
## The following object is masked from 'package:graphics':
##
## legend
## Loading required package: quantmod
## Loading required package: TTR
## Version 0.4-0 included new data defaults. See ?getSymbols.
plot + geom_col() +
theme_tq()
plot + geom_line() +
geom_point() +
theme_tq()
plot + geom_col() +
theme_tq_dark()
plot + geom_line() +
geom_point() +
theme_tq_green()
# bbplot
library(bbplot)
plot + geom_col() +
bbc_style() +
scale_fill_manual(values = c("#FAAB18", "#1380A1","#588300")) +
scale_color_manual(values = c("#FAAB18", "#1380A1","#588300"))
plot + geom_line() +
geom_point() +
bbc_style() +
scale_color_manual(values = c("#FAAB18", "#1380A1","#588300"))
https://github.com/sunlightlabs/chartoff
# sunlight
library("grid")
source("sunlight_R_style.R")
## Warning: `legend.margin` must be specified using `margin()`. For the old
## behavior use legend.spacing
plot + geom_col() +
scale_fill_sunlight(palette = "Set1") +
scale_colour_sunlight(palette = "Set1")
plot + geom_line() +
scale_fill_sunlight(palette = "Set1") +
scale_colour_sunlight(palette = "Set1")