Chapter 2. Beyond the Basics: Adjusting Key Parameters

In this chapter, we will cover:

  • Setting colors of points, lines, and bars
  • Setting plot background colors
  • Setting colors for text elements: axis annotations, labels, plot titles, and legends
  • Choosing color combinations and palettes
  • Setting fonts for annotations and titles
  • Choosing plotting point symbol styles and sizes
  • Choosing line styles and width
  • Choosing box styles
  • Adjusting axis annotations and tick marks
  • Formatting log axes
  • Setting graph margins and dimensions

Introduction

In this chapter, we will learn about some of the simplest yet most important settings and parameters of graphs in R base graphics. Learning how to adjust colors, sizes, margins, and styles of various graph elements such as points, lines, bars, axes, and titles will give us the ability to improve upon the basic graph commands we learnt in Chapter 1.

In the previous chapter, we got a glimpse of the different types of graphs that can be made in R using small snippets of code. Now, we will learn how to modify the fundamental building blocks of those graphs to better suit our needs.

The R base library has very powerful graphical capabilities. While you can produce pretty much any type of graph with a couple of lines of code, the default layout and look of the graph is often very basic. Sometimes, you may run into problems such as axis labels and titles getting chopped off at the edges or the legend size or position may mask part of your graph. Sometimes, the default color combinations may not be suitable for presentation or publication.

In this chapter we will go through the relevant names and accepted values of different arguments and arguments to graph functions. We will take a closer look at the par() function, which we briefly introduced in the previous chapter.

Reading and trying out all the recipes in this chapter is highly recommended as it will give you a very good hands-on grasp of certain aspects of graph manipulation, which you are likely to use a lot in any visual analysis in R.

Let's get started!

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset