examples/rbar.R

library(here)
library(ggplot2)

fruits <- read.csv(here("datasets", "fruits.csv"), stringsAsFactors = FALSE)

devtools::load_all()
## If that doesn't work, uncomment and run these lines
## source(here("R", "bbc_theme.R"))
## source(here("R", "helpers.R"))
## bbc_colours <- read.csv(here("datasets", "bbc_colours.csv"))

simple_bar <- ggplot(data= subset(fruits, year==2016), aes(x=fruits, y=value))+
    barplot_theme() +
    geom_bar(stat="identity", fill=get_colour("red", 3) , width=0.8) +
    coord_flip() +
    labs(title = "Title", subtitle = "Subtitle",
         caption = "Source: Source", y = "Value", x = "Fruits") +
    scale_y_continuous(expand=c(0,0), position="right", limits=c(0,90))

simple_bar


simple_bar2 <- left_align(simple_bar, c("title", "subtitle", "caption"))
grid::grid.draw(simple_bar2)

double_bar <- ggplot(data= fruits, aes(x=fruits, y=value, fill=as.character(year)))+
  geom_bar(position='dodge', stat="identity") +
  coord_flip() +
  barplot_theme() +
  labs(title = "Title", subtitle = "Subtitle", caption = "Source: Source",
       y = "Kg", x = "Fruits") +
    scale_colour_manual(values=
                            subset(bbc_colours, colour %in% c("red", "green") & shade==6)$code) +
    scale_y_continuous(expand=c(0,0), position="right") +
    theme(legend.title=element_blank())

double_bar

double_bar2 <- left_align(double_bar, c("title", "subtitle", "caption"))
grid::grid.draw(double_bar2)
bbcuffer/bbcfigr documentation built on May 17, 2019, 8:05 a.m.