Chapter 13 Plotrix for complex visualizations

Alex Wan and Junyang Jiang

13.1 Overview

Our graphs have to be informative and attractive to the audience to get their attention.

This section covers how we can use specialized plots and accessories functions in plotrix to easily build complex visualizations.

13.2 Plotrix

In plotrix, we have many functionalities. A brief description of a selcted few of them is as follows:

  • barNest: Display a nested breakdown of numeric values
  • zoomInPlot: Display a plot with rectangular section expanded in an adjacent plot
  • fan.plot: Display a fan plot
  • pie3D: Display a 3D pie chart
  • pyramid.plot: Pyramid plot

13.2.1 barNest example

In a nested bar chart, we can break down the elements of the data frame by one or more categorical elements and display the breakdown as a bar plot. It first takes as input the dependent and independent variables, as columns of a dataframe, along with the colors to be used in the plot. The showall parameter indicates whether to display bars for the entire breakdown, while the shrink parameter determines the proportion to shrink the width of bars at each level. The trueval parameter returns the proportion of of the response variable equal to ‘trueval’.

We can also set Nwidths to TRUE, if we want to scale the the widths of bars to the number of observations.

13.3 zoomInPlot example

The zoomInPlot function allows us to display one plot on the left half, and an expanded section of the plot on the right half, with lines showing the expansion.

It takes as input two vectors, x and y. We can also use the rxlim and rylim parameters to dictate the limits of the expanded section.

13.4 fan.plot example

The fan.plot function displays numerical values as arcs of overlapping sectors. It takes as input the vector of numbers we want to plot, as well as the max.span which will be the angle of the maximum sector in radians. In the example below, the span is set to pi, so the max sector will be a half circle. The labels parameter provides the corresponding lables to the different sectors, while the ticks parameter determines the total number of ticks around the span.

13.5 pie3D example

The pie3D function displays a 3D pie chart with optional labels. It takes as input a numeric vector where each value is a sector in the pie chart, as well as the optional labels for each sector. The radius parameter determines how large the pie is, while the explode parameter determines how much the pie sectors “explodes” outward from the center.

13.6 pyramid.plot example

The pyramid.plot function displays a pyramid of opposing horizontal bar plots. Its primary intention is for the construction of population pyramids, although it can also display other types of opposed bar charts. It takes as input two vectors of numbers, one to be displayed on the left and the other on the right. It also needs a label vector to be displayed in the middle, which should contain a label for each left or right value, even if empty. We can also specify the colors to be used on the left and right, while setting show.values to TRUE will display the corresponding values at the end of the bars.