Chapter 6. Creating Bar, Dot, and Pie Charts

In this chapter, we will cover the following recipes:

  • Creating bar charts with more than one factor variable
  • Creating stacked bar charts
  • Adjusting the orientation of bars – horizontal and vertical
  • Adjusting bar widths, spacing, colors, and borders
  • Displaying values on top of or next to the bars
  • Placing labels inside bars
  • Creating bar charts with vertical error bars
  • Modifying dot charts by grouping variables
  • Making better readable pie charts with clockwise-ordered slices
  • Labeling a pie chart with percentage values for each slice
  • Adding a legend to a pie chart

Introduction

In this chapter, we will look at bar, dot, and pie charts in detail. Bar charts are used commonly in reporting business data and scientific analysis. We will see how we can enhance the basic bar charts in R by adjusting some parameters in the base graphics library. There are a few different packages that can be used to make bar charts (most notably lattice and ggplot2). However, in this chapter, we will see how we can create many useful variations of bar graphs by using only the base library functions.

We will also look at a few recipes on pie charts—easily the most criticized type of chart in the scientific community, but also one of the most popular in the business world. While it is true that pie charts often obscure the data and are hard to read, the recipes in this chapter offer some ways to make pie charts more readable.

Some of the parameters are obscure and, sometimes, it might not be absolutely clear as to what values an argument can take. It is best to experiment as you go along and try out the recipes. You might not understand a function or its arguments fully until you have tried to graph a few of your own datasets. If you get stuck at any point, first look at the help file of the relevant function. If you are still stuck after having read the help files, then you can search the R mailing list (http://www.r-project.org/mail.html) and forums (http://r.789695.n4.nabble.com/ and http://stackoverflow.com/questions/tagged/r). Often, the problems one comes across are common and might have already been addressed by the R community in response to someone else's question.

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

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