10 Advanced Plotting with ggplot – I

 

This chapter covers

  • Making presentation-ready line graphs and bar plots
  • Customizing plot axes so that you can express these important plot elements to your own specifications
  • Labeling interesting aspects of a plot with annotations
  • Using color effectively in your plots

Different types of data lend themselves better to different types of plots. Knowing which type of plot you’ll need is really half the battle. Luckily ggplot is quite capable of making a wide range of plots. In this chapter, we’ll demonstrate how make line graphs and bar plots with a lot of attention given toward the customization of plot elements such the axes and legends. This chapter will provide a plethora of tips on which plot options might be used depending on what information is important to convey. All of this is so that later, when the time comes, a well-crafted plot can be made with a minimum of frustration. There are many, many ggplot examples shown in this chapter and, while that might overwhelm, it’s hoped that the provided code listings illuminate many of the plotting features in ggplot, and, serve as reusable code for your future plots.

10.1  Making Line Graphs

10.1.1    Using geom_line()

10.1.2    Using geom_line() and geom_point()

10.1.3    Using geom_area() to make a line graph

10.2  Working with Bar Plots

10.2.1    Vertical Bar Plots

10.2.2    Clustered Bar Plots

10.2.3    Stacked Bar Plots

10.3  Summary