class: center, top, title-slide # Communicating Data Insights with Visuals using ggplot2 ## Oluwafemi Oyedele ### Research Fellow, IITA
Abuja R Users Group ### Mar 26, 2022
Updated: Mar 26, 2022 --- ## About me .left-column[ <img src="img/pix.jpg" width="2385" style="display: block; margin: auto auto auto 0;" /> ] .right-column[ - I am a Agrometeorologist and Crop Simulation modeler - I am a member of R4DS online learning community - I am also a active member of the TidyTuesday project - I love reading books in my spare time -
: [Oluwafemi Oyedele](https://www.linkedin.com/in/oluwafemioyedele/) -
: [@OluwafemOyedele](https://twitter.com/OluwafemOyedele) 👍 -
: [https://github.com/BB1464/BB1464](https://github.com/BB1464/BB1464) -
: [https://statisticalinference.netlify.app](https://statisticalinference.netlify.app) 😄 ] --- # **Agenda** - Introduction to the Grammar of Graphics - We will be looking at the different layers that is in ggplot2 - The focus of this talk will be on the 20% that is useful 80% of the time - More in-depth coverage is available via resources I will release later. - **My goal is to make you excited about ggplot2!** - I will entertain **questions** at the end - **Github link to get the materials**: https://github.com/BB1464/R-Ladies-Abuja --- # Packages Used Today This workshop focuses on data visualization with [`ggplot2`](https://ggplot2.tidyverse.org). -- `ggplot2` is a system for declaratively creating graphics, based on The Grammar of Graphics. You provide the data, tell `ggplot2` how to map variables to `aesthetics`, what graphical primitives to use (`geoms`), and it takes care of the details. -- You can install `ggplot2` with the following: ```r install.packages("ggplot2") ``` Or the development version from GitHub: ```r install.packages("devtools") ``` ```r devtools::install_github("tidyverse/ggplot2") ``` ```r library(ggplot2) # Create Elegant Data Visualizations Using the Grammar of Graphics, CRAN v3.3.5 ``` --- # Grammar of Graphics .pull-right[![](img/wilkinson.jpeg)] .pull-left[ - First published in 1999 - A theoretical deconstruction of data graphics - Foundation for many graphic applications - The Grammar of Graphics can be applied to every type of plot - Concisely describe components .pull-left[![](img/ggplot2.png)] ] --- # Grammar of Graphics ![](img/tom1.png) --- # Grammar of Graphics .pull-right[![](img/tom_data.png)] - Your dataset - Tidy format - There is no visualization without a dataset --- # Grammar of Graphics .pull-right[![](img/tom_mapping.png)] - **Aesthetics mapping**: links variable in the data to graphical properties in the geometry. - We can specify the following properties within the aestetic mapping (colour, shape, alpha, fill, size). --- # Grammar of Graphics .pull-right[![](img/tom_statistics.png)] - Transform input variables to displayed values: - Bins for histogram - Summary statistics for boxplot using `stat_boxplot()` - No. of observations in a category for bar chart `stat_count` - Even tidy data may need some transformation - The statistics is linked to the geometry - It is implicit in many plot-types but they can be done prior to plotting. --- # Grammar of Graphics .pull-right[![](img/tom_scales.png)] - Scales help us to control the mapping from data to aesthetics - Scales also provide the tools that let you interpret the plot: the axes and legends. - Scales are automatically generated in ggplot and can be customized - log scale - We can also specify limit within the scale - Scales help you interpret the plot - Categories -> color - Numeric -> position --- # Grammar of Graphics .pull-right[![](img/tom_geometries.png)] - Geometries help us to interpret the aesthetics as graphical representation - Determines your plot type - bar chart `geom_bar()` - scatter `geom_point()` - box plot `geom_boxplot()` - histogram `geom_histogram()` - ... --- # Grammar of Graphics .pull-right[![](img/tom_facets.png)] - Divide your data into panels using one or two groups - Allows you to look at smaller subsets of data --- # Grammar of Graphics .pull-right[![](img/tom_coordinates.png)] - A coordinate system, maps the position of objects onto the plane of the plot. - It is also the physical mapping of the aesthetics to the paper - Coordinate systems affect all position variables simultaneously and differ from scales in that they also change the appearance of the geometric objects. - Coordinate systems control how the axes and grid lines are drawn. --- # Grammar of Graphics .pull-right[![](img/tom_theme.png)] - This controls the overall look of the plot - Spans every part of the graphic that is not linked to the data - Themes give you control over things like fonts, ticks, panel strips, and backgrounds --- ![](img/horst_ggplot.jpeg) --- - `The Data Layer` specifies the data being plotted .center[ ![](img/ge_data.png) ] ```r head(iris,2) ``` ``` ## Sepal.Length Sepal.Width Petal.Length Petal.Width Species ## 1 5.1 3.5 1.4 0.2 setosa ## 2 4.9 3.0 1.4 0.2 setosa ``` ```r ggplot(data = iris) ``` <img src="index_files/figure-html/unnamed-chunk-5-1.png" style="display: block; margin: auto;" /> --- - Aesthetic mapping ```r ggplot(data = iris, mapping = aes( x = Sepal.Length, y = Sepal.Width, colour=Species,shape=Species), alpha=0.5 ) ``` <img src="index_files/figure-html/unnamed-chunk-6-1.png" style="display: block; margin: auto;" /> --- # Geoms `ggplot2` has 53 `geometry` at the moments but we are going to look at just few `geometry` today. But I will release some useful resources at the end where you can learn further on what is not covered here. - We can view all the geoms with this function below ```r apropos('^geom_') ``` ``` ## [1] "geom_abline" "geom_area" "geom_bar" ## [4] "geom_bin_2d" "geom_bin2d" "geom_blank" ## [7] "geom_boxplot" "geom_col" "geom_contour" ## [10] "geom_contour_filled" "geom_count" "geom_crossbar" ## [13] "geom_curve" "geom_density" "geom_density_2d" ## [16] "geom_density_2d_filled" "geom_density2d" "geom_density2d_filled" ## [19] "geom_dotplot" "geom_errorbar" "geom_errorbarh" ## [22] "geom_freqpoly" "geom_function" "geom_hex" ## [25] "geom_histogram" "geom_hline" "geom_jitter" ## [28] "geom_label" "geom_line" "geom_linerange" ## [31] "geom_map" "geom_path" "geom_point" ## [34] "geom_pointrange" "geom_polygon" "geom_qq" ## [37] "geom_qq_line" "geom_quantile" "geom_raster" ## [40] "geom_rect" "geom_ribbon" "geom_rug" ## [43] "geom_segment" "geom_sf" "geom_sf_label" ## [46] "geom_sf_text" "geom_smooth" "geom_spoke" ## [49] "geom_step" "geom_text" "geom_tile" ## [52] "geom_violin" "geom_vline" ``` --- # Scatter plot ```r ggplot(data = iris, mapping = aes( x = Sepal.Length, y = Sepal.Width, colour=Species,shape=Species), alpha=0.5 )+ geom_point() ``` <img src="index_files/figure-html/unnamed-chunk-8-1.png" style="display: block; margin: auto;" /> --- - Variable that is not link to the data set ```r ggplot(data = iris, mapping = aes( x = Sepal.Length, y = Sepal.Width,shape=Species,colour='blue'))+ geom_point() ``` <img src="index_files/figure-html/unnamed-chunk-9-1.png" style="display: block; margin: auto;" /> --- - Removing the color from the mapping ```r ggplot(data = iris, mapping = aes( x = Sepal.Length, y = Sepal.Width,shape=Species))+ geom_point(colour='blue') ``` <img src="index_files/figure-html/unnamed-chunk-10-1.png" style="display: block; margin: auto;" /> --- <img src="img/tom_need1.png" width="1735" style="display: block; margin: auto;" /> --- ```r ggplot(data=faithful) + geom_point(aes(x = eruptions, y = waiting, colour = eruptions < 3)) ``` <img src="index_files/figure-html/unnamed-chunk-12-1.png" style="display: block; margin: auto;" /> --- # Bar plot ```r ggplot(data = iris)+ geom_bar(mapping = aes(x = Species,fill=Species),data = NULL,width = 0.7) ``` <img src="index_files/figure-html/unnamed-chunk-13-1.png" style="display: block; margin: auto;" /> --- # Bar plot where we fail to define the stat ```r ggplot(data = iris, mapping = aes( x = Species, y= Sepal.Length, fill=Species) )+ geom_bar(width = 0.9) ``` ``` ## Error in `f()`: ## ! stat_count() can only have an x or y aesthetic. ``` <img src="index_files/figure-html/unnamed-chunk-14-1.png" style="display: block; margin: auto;" /> --- ```r ggplot(data = iris, mapping = aes( x = Species, y= Sepal.Length, fill=Species) )+ geom_bar(width = 0.9,stat='identity') ``` <img src="index_files/figure-html/unnamed-chunk-15-1.png" style="display: block; margin: auto;" /> --- - This shows the proportion for each cut ```r ggplot(data = diamonds,mapping = aes(x = color,y=price,fill=cut))+ geom_col(position = 'fill') ``` <img src="index_files/figure-html/unnamed-chunk-16-1.png" style="display: block; margin: auto;" /> --- - This shows the proportion of the cut ```r ggplot(data = diamonds,mapping = aes(x = reorder(color,price,FUN=mean),y=price,fill=cut))+ geom_bar(stat='summary',fun=mean)+xlab('Diamond colour') ``` <img src="index_files/figure-html/unnamed-chunk-17-1.png" style="display: block; margin: auto;" /> --- # Box plot `geom_boxplot()` ```r ggplot(data = iris, mapping = aes( x = Species, y = Sepal.Width, fill=Species))+ geom_boxplot()+geom_jitter()+ stat_summary(fun = mean,geom = 'point',shape=23,fill='white',size=2.5) ``` <img src="index_files/figure-html/unnamed-chunk-18-1.png" style="display: block; margin: auto;" /> --- # Histogram : `geom_histogram` ```r ggplot(data = iris)+ geom_histogram( mapping = aes(x = Sepal.Length,fill=Species) ) ``` ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` <img src="index_files/figure-html/unnamed-chunk-19-1.png" style="display: block; margin: auto;" /> --- - Default behavior of `goem_histogram` is equivalent to the following. ```r ggplot(iris, aes(x = Sepal.Length, y = after_stat(count),fill=Species)) + geom_histogram() ``` ``` ## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`. ``` <img src="index_files/figure-html/unnamed-chunk-20-1.png" style="display: block; margin: auto;" /> --- - line graph with`stat_summary` ```r ggplot(data = economics,mapping = aes(x = date,y = uempmed))+ stat_summary(fun = mean,geom = 'line') ``` <img src="index_files/figure-html/unnamed-chunk-21-1.png" style="display: block; margin: auto;" /> --- # Violin plot ```r ggplot(data = iris,mapping = aes(x = Species,y = Petal.Length,fill=Species))+geom_violin() ``` <img src="index_files/figure-html/unnamed-chunk-22-1.png" style="display: block; margin: auto;" /> --- - `Statistics` - Statistical transformations, summarize the data: for example, binning and counting observations to create a histogram, or fitting a linear model. - The statistics layer allows you plot statistical values calculated from the data - You’ve already used many of ggplot2’s stats because they’re used behind the scenes to generate many important `geoms` - The function below shows the number of statistics available in ggplot2 ```r apropos('^stat_') ``` ``` ## [1] "stat_bin" "stat_bin_2d" "stat_bin_hex" ## [4] "stat_bin2d" "stat_binhex" "stat_boxplot" ## [7] "stat_contour" "stat_contour_filled" "stat_count" ## [10] "stat_density" "stat_density_2d" "stat_density_2d_filled" ## [13] "stat_density2d" "stat_density2d_filled" "stat_ecdf" ## [16] "stat_ellipse" "stat_function" "stat_identity" ## [19] "stat_qq" "stat_qq_line" "stat_quantile" ## [22] "stat_sf" "stat_sf_coordinates" "stat_smooth" ## [25] "stat_spoke" "stat_sum" "stat_summary" ## [28] "stat_summary_2d" "stat_summary_bin" "stat_summary_hex" ## [31] "stat_summary2d" "stat_unique" "stat_ydensity" ``` --- `Statistics`:`stat_boxplot` ```r ggplot(data = iris, mapping = aes( x = reorder(Species,Sepal.Width,FUN=median), y = Sepal.Width, fill=Species))+ stat_boxplot(geom = 'errorbar')+ geom_boxplot(notch = TRUE)+geom_jitter()+ stat_summary(fun = mean,geom = 'point',shape=23,fill='white',size=2.5)+xlab('Species') ``` <img src="index_files/figure-html/unnamed-chunk-24-1.png" style="display: block; margin: auto;" /> --- - stat_identity leaves the data unchanged ```r ggplot(data=mtcars)+stat_identity(mapping = aes(x = wt,y = mpg)) ``` <img src="index_files/figure-html/unnamed-chunk-25-1.png" style="display: block; margin: auto;" /> --- - Statistical Transformation for bar plot <img src="img/visualization-stat-bar.png" width="3867" style="display: block; margin: auto;" /> - You can find out which `stat` each `geom` uses by looking at the default value of the `stat` argument of the help page. - What it the default `stat` for `geom_bar`? --- - Bar plot with error bars to show the level of precision around the mean ```r ggplot(data=diamonds,aes(x = cut, y = price)) +stat_summary( geom = "bar", fun = "mean", alpha = .6)+ stat_summary( geom = "errorbar", fun.data = "mean_se", width = .2)+ stat_summary( geom = "point", fun = "mean") ``` <img src="index_files/figure-html/unnamed-chunk-27-1.png" style="display: block; margin: auto;" /> --- - Scatter plot showing the mean data point in red ```r ggplot(mpg)+ geom_jitter(mapping = aes(x = class,y = hwy),width = 0.2)+ stat_summary(mapping = aes(x = class,y=hwy),fun = mean,geom='point',colour='red') ``` <img src="index_files/figure-html/unnamed-chunk-28-1.png" style="display: block; margin: auto;" /> --- - Here I added the best fit line alongside with the 95% confidence interval ```r ggplot(mpg, aes(x = cty, y = displ)) + geom_point(alpha = 0.4, size = 2) + scale_x_log10() + geom_smooth(method = "lm") ``` ``` ## `geom_smooth()` using formula 'y ~ x' ``` <img src="index_files/figure-html/unnamed-chunk-29-1.png" style="display: block; margin: auto;" /> --- ```r iris |> ggplot(aes(x = Species, y = Sepal.Length))+ stat_summary(geom = 'pointrange',fun.max = max,fun.min = min,fun = mean) ``` <img src="index_files/figure-html/unnamed-chunk-30-1.png" style="display: block; margin: auto;" /> --- # `Scales` - `Scales` in ggplot2 control the mapping from data to aesthetics. They take your data and turn it into something that you can see, like size, colour, position or shape. - `Scales` also provide the tools that let you interpret the plot: the axes and legends. You can generate plots with ggplot2 without knowing how scales work, but understanding scales and learning how to manipulate them will give you much more control. --- - `ggplot2 has a total of 122 scales` but hear I choose to only show the first 50. ```r apropos('^scale_')|> head(n=50) ``` ``` ## [1] "scale_alpha" "scale_alpha_binned" ## [3] "scale_alpha_continuous" "scale_alpha_date" ## [5] "scale_alpha_datetime" "scale_alpha_discrete" ## [7] "scale_alpha_identity" "scale_alpha_manual" ## [9] "scale_alpha_ordinal" "scale_color_binned" ## [11] "scale_color_brewer" "scale_color_continuous" ## [13] "scale_color_date" "scale_color_datetime" ## [15] "scale_color_discrete" "scale_color_distiller" ## [17] "scale_color_fermenter" "scale_color_gradient" ## [19] "scale_color_gradient2" "scale_color_gradientn" ## [21] "scale_color_grey" "scale_color_hue" ## [23] "scale_color_identity" "scale_color_manual" ## [25] "scale_color_ordinal" "scale_color_steps" ## [27] "scale_color_steps2" "scale_color_stepsn" ## [29] "scale_color_viridis_b" "scale_color_viridis_c" ## [31] "scale_color_viridis_d" "scale_colour_binned" ## [33] "scale_colour_brewer" "scale_colour_continuous" ## [35] "scale_colour_date" "scale_colour_datetime" ## [37] "scale_colour_discrete" "scale_colour_distiller" ## [39] "scale_colour_fermenter" "scale_colour_gradient" ## [41] "scale_colour_gradient2" "scale_colour_gradientn" ## [43] "scale_colour_grey" "scale_colour_hue" ## [45] "scale_colour_identity" "scale_colour_manual" ## [47] "scale_colour_ordinal" "scale_colour_steps" ## [49] "scale_colour_steps2" "scale_colour_stepsn" ``` --- # `Modifying scales` - A scale is required for every aesthetic used on the plot. When you write: ```r ggplot(mpg, aes(displ, hwy)) + geom_point(aes(colour = class)) ``` <img src="index_files/figure-html/unnamed-chunk-31-1.png" style="display: block; margin: auto;" /> --- `What actually happens is this:` ```r ggplot(mpg, aes(displ, hwy)) + geom_point(aes(colour = class)) + scale_x_continuous() + scale_y_continuous() + scale_colour_discrete() ``` <img src="index_files/figure-html/unnamed-chunk-32-1.png" style="display: block; margin: auto;" /> --- `placing the x axis on log10` ```r ggplot(mpg, aes(displ, hwy,colour=class)) + geom_point() + scale_x_log10() ``` <img src="index_files/figure-html/unnamed-chunk-33-1.png" style="display: block; margin: auto;" /> --- `Modifying the colour of the scatter plot using scale_colour_discrete` ```r ggplot(data = mpg,mapping = aes(x = displ,y = hwy,colour=class))+ geom_point()+ scale_color_brewer(name='Class',palette = 'Set1') ``` <img src="index_files/figure-html/unnamed-chunk-34-1.png" style="display: block; margin: auto;" /> --- - Here I specified that the type should be qualitative but we can also use sequencial or diverging ```r ggplot(mpg) + geom_point(aes(x = displ, y = hwy, colour = class)) + scale_colour_brewer(type = 'qual') ``` <img src="index_files/figure-html/unnamed-chunk-35-1.png" style="display: block; margin: auto;" /> --- `Modifying the colour of the bar plot` ```r ggplot(data = iris, mapping = aes(x = Species,fill=Species)) + geom_bar()+ scale_fill_brewer(name='Species',palette = 'Dark2') ``` <img src="index_files/figure-html/unnamed-chunk-36-1.png" style="display: block; margin: auto;" /> --- - Here I placed the y axis on log 10 and then I specified the breaks for the y axis ```r ggplot(mpg) + geom_point(aes(x = displ, y = hwy)) + scale_x_continuous(breaks = c(3, 5, 6)) + scale_y_continuous(trans = 'log10') ``` <img src="index_files/figure-html/unnamed-chunk-37-1.png" style="display: block; margin: auto;" /> --- `How to supply manual colour to ggplot2` ```r ggplot(data = mpg,mapping = aes(x = displ,y = hwy,colour=class))+ geom_point()+ scale_colour_manual(name='Class',values = c('red','blue','green','cyan', 'gray50','pink','black')) ``` <img src="index_files/figure-html/unnamed-chunk-38-1.png" style="display: block; margin: auto;" /> --- - This are all linked to the scales of the visualization <img src="img/scale-guides.png" width="992" style="display: block; margin: auto;" /> --- `How to creat breaks in the x axis` ```r ggplot(data = economics,mapping = aes(x = date,y = unemploy))+ geom_line()+ scale_x_date(date_breaks = '10 years') ``` <img src="index_files/figure-html/unnamed-chunk-40-1.png" style="display: block; margin: auto;" /> --- - Supplying labels to the x axis ```r ggplot(data = iris, mapping = aes(x =Species,fill=Species))+ geom_bar()+ scale_fill_brewer(name='Species',palette='Dark2')+ scale_x_discrete(name='Species', labels=c('setosa\n(N=50)','versicolor\n(N=50)','virginica\n(N=50)')) ``` <img src="index_files/figure-html/unnamed-chunk-41-1.png" style="display: block; margin: auto;" /> --- # Coordinate system in `ggplot2` - The coordinate system, describes how data coordinates are mapped to the plane of the graphic. It also provides axes and grid lines to help read the graph. We normally use the Cartesian coordinate system, but a number of others are available, including polar coordinates and map projections. - We can view all the available coordinate system with the function below ![](img/visualization-coordinate-systems.png) --- - We can zoom into the plot within the `coord_cartesian` by just specifying the limit ```r ggplot(mpg) + geom_bar(aes(x = class)) + coord_cartesian(ylim = c(0, 40)) ``` <img src="index_files/figure-html/unnamed-chunk-42-1.png" style="display: block; margin: auto;" /> --- - We can ensure that the x and y axis start from zero ```r ggplot(mpg) + geom_bar(aes(x = class)) + coord_cartesian(ylim = c(0, 40),expand=expansion(mult = 0,add = 0)) ``` ``` ## Warning in if (!expand) {: the condition has length > 1 and only the first ## element will be used ## Warning in if (!expand) {: the condition has length > 1 and only the first ## element will be used ``` <img src="index_files/figure-html/unnamed-chunk-43-1.png" style="display: block; margin: auto;" /> --- # Facetting - The facet defines how data is split among panels. The default facet (`facet_null()`) puts all the data in a single panel, while `facet_wrap()` and `facet_grid()` allows you to specify different types of small multiples - The function below shows the number of facet available in `ggplot2` ```r apropos('^facet_') ``` ``` ## [1] "facet_grid" "facet_null" "facet_wrap" ``` --- `facet_wrap` ```r ggplot(data = mpg)+ geom_point(mapping = aes(x = displ, y = hwy)) + facet_wrap(~ class, nrow = 2) ``` <img src="index_files/figure-html/unnamed-chunk-45-1.png" style="display: block; margin: auto;" /> --- `facet_grid` ```r ggplot(data = mpg) + geom_point(mapping = aes(x = displ, y = hwy)) + facet_grid(drv ~ cyl) ``` <img src="index_files/figure-html/unnamed-chunk-46-1.png" style="display: block; margin: auto;" /> --- - We can customize the plot background with the themes below ```r apropos('^*theme_()') ``` ``` ## [1] "theme_bw" "theme_classic" "theme_dark" "theme_get" ## [5] "theme_gray" "theme_grey" "theme_light" "theme_linedraw" ## [9] "theme_minimal" "theme_replace" "theme_set" "theme_test" ## [13] "theme_update" "theme_void" ``` ```r length(theme_get()) ``` ``` ## [1] 93 ``` ```r theme_get() |> head(1) ``` ``` ## $line ## List of 6 ## $ colour : chr "black" ## $ size : num 0.5 ## $ linetype : num 1 ## $ lineend : chr "butt" ## $ arrow : logi FALSE ## $ inherit.blank: logi TRUE ## - attr(*, "class")= chr [1:2] "element_line" "element" ``` --- - To get the default argument for plot title in `ggplot2` ```r theme_get()$plot.title ``` ``` ## List of 11 ## $ family : NULL ## $ face : NULL ## $ colour : NULL ## $ size : 'rel' num 1.2 ## $ hjust : num 0 ## $ vjust : num 1 ## $ angle : NULL ## $ lineheight : NULL ## $ margin : 'margin' num [1:4] 0points 0points 5.5points 0points ## ..- attr(*, "unit")= int 8 ## $ debug : NULL ## $ inherit.blank: logi TRUE ## - attr(*, "class")= chr [1:2] "element_text" "element" ``` --- # Theme customization - We can use `theme()` if we want to tweak the display of an existing theme. - `The Themes Layer` refers to all non-data ink: i.e. titles, labels, fonts, background, gridlines, and legends. - Any text element in the theme can be modified with element_text() - Any line element can be modified with element_line() - Any rect element can be modified with element_rect() - Theming defines the feel and look of your final visualization and is something you will normally defer to the final polishing of the plot. - There are around 40 unique elements that control the appearance of the plot. They can be roughly grouped into five categories: `plot`, `axis`, `legend`, `panel` and `facet`. --- ![](img/theme_elements.png) --- `Minimal theme` ```r ggplot(mpg) + geom_bar(aes(y = class)) + facet_wrap(~year) + theme_minimal() ``` <img src="index_files/figure-html/unnamed-chunk-49-1.png" style="display: block; margin: auto;" /> --- `Theme customization` ```r ggplot(mpg)+geom_bar(aes(y = class))+facet_wrap( ~ year)+ labs( title = "Number of car models per class", caption = "source:http://fueleconomy.gov", x = NULL, y = NULL )+ scale_x_continuous(expand = c(0, NA))+theme_minimal()+ theme( text = element_text('Avenir Next Condensed'), strip.text = element_text(face = 'bold', hjust = 0), plot.caption = element_text(face = 'italic'), panel.grid.major= element_line('white', size = 0.5), panel.grid.minor=element_blank(), panel.grid.major.y = element_blank(), panel.ontop=TRUE ) ``` <img src="index_files/figure-html/unnamed-chunk-50-1.png" style="display: block; margin: auto;" /> --- # Saving the plot ```r ggsave('plot.name.png',plot = last_plot,width = 9,height = 6,units = 'cm',dpi = 450) ``` --- # Resources * [ggplot2: Elegant Graphics for Data Analysis](https://ggplot2-book.org/introduction.html) This is a very good resources to learn data visualization and it was written by Hadley Wickham the author of `ggplot2` * [ggplot2 website](http://ggplot2.tidyverse.org/) * [R for Data Science](http://r4ds.had.co.nz/) online textbook by Garrett Grolemund and Hadley Wickham. One of many good R texts available, but importantly it is free and focuses on the [`tidyverse`](http://tidyverse.org/) collection of R packages which are the modern standard for data manipulation and visualization in R. * [Advanced R](http://adv-r.had.co.nz/) online textbook by Hadley Wickham. A great source for more in-depth and advanced R programming. * [Useful RStudio cheatsheets](https://www.rstudio.com/resources/cheatsheets/) on `ggplot2`. * [Fundamentals of Data Visualization](https://book4you.org/book/5618179/8693c0) This is a very good book written by Claus O. Wilke which talks about data Visualization in R using the tidyverse philosophy * [Storytelling with Data](https://book4you.org/book/19209707/be7fa6) This book is a data visualization guide for business professional written by Cole Nussbaumer Knaflic --- # Acknowledgement Special thanks to all the people who made this presentation successful: - I will like to thank **@Abuja R Users Group** organisers for giving me the opportunity to present this presentation. - I will also like to thanks **Yihui Xie** for developing the *{knitr}* and *{xaringan}* package and also **Garrick Aden-Buie** for developing the *{xaringanthemer}* package. - I will also like to appreciate **Thomas Lin Pedersen** for giving a great talk on plotting anything with ggplot2 and this also inspired my talk. - Slides for this talk was created with the [**xaringan package**](https://github.com/yihui/xaringan) --- class: middle, center, hide-logo, question background-image: url(https://upload.wikimedia.org/wikipedia/commons/3/39/Naruto_Shiki_Fujin.svg) background-size: contain # Questions