Title in GGPLOT charts

Load the libraries

# library

library(ggplot2)   # For plotting

Sample dataset

We will use mpg dataset which is a built-in data set and will be available to use.

Lets seen the data on the screen, we have used the head() command which shows only 6 rows from the top

head(mpg)
FALSE # A tibble: 6 × 11
FALSE   manufacturer model displ  year   cyl trans      drv     cty   hwy fl    class 
FALSE   <chr>        <chr> <dbl> <int> <int> <chr>      <chr> <int> <int> <chr> <chr> 
FALSE 1 audi         a4      1.8  1999     4 auto(l5)   f        18    29 p     compa…
FALSE 2 audi         a4      1.8  1999     4 manual(m5) f        21    29 p     compa…
FALSE 3 audi         a4      2    2008     4 manual(m6) f        20    31 p     compa…
FALSE 4 audi         a4      2    2008     4 auto(av)   f        21    30 p     compa…
FALSE 5 audi         a4      2.8  1999     6 auto(l5)   f        16    26 p     compa…
FALSE 6 audi         a4      2.8  1999     6 manual(m5) f        18    26 p     compa…

Create a simple bar plot using mpg dataset

pl <- ggplot (data = mpg)
pl <- pl + geom_bar(aes(  x    = class, fill = class))
pl <- pl + theme_bw()
pl <- pl + scale_fill_viridis_d()
pl <- pl + labs(title = "Miles per gallon and displacement")
pl <- pl + theme(aspect.ratio=9/16)
pl
plot of chunk unnamed-chunk-3

Test