Category Archives: R Graphics

RColorBrewer Palettes

Color Groups

RColorBrewer is an R packages that uses the work from http://colorbrewer2.org/ to help you choose sensible colour schemes for figures in R.  The colors are split into three group, sequential, diverging, and qualitative. 

  • Sequential – Light colours for low data, dark for high data
  • Diverging –  Light colours for mid-range data, low and high contrasting dark colours
  • Qualitative – Colours designed to give maximum visual difference between classes
Posted in R Colors, R Graphics | Leave a comment

Trellis Graphs

UnderConstruction

Back | Next

Posted in R Graphics | Leave a comment

Building Layered Plots

Layered plots are one way to achieve new insight and actionable intelligence when working with complex data.  ggplot is well suited for layered plots.

Data Pre-Processing

To make graphs with ggplot(), the data must be in a data frame and in “long” (as opposed to wide) format.  Converting between “wide” and “long” data formats is facilitated with the reshape2 package.  Specifically, the melt() function converts wide to long format, and the cast() function converts long to wide format.  The following code block presents examples of the two data formats.

Posted in ggplot2, R Graphics, R Programming | Leave a comment

R Graphics: Color Ramp Functions

Color ramp functions in R simplify color selection and assignment.  Visual reference examples are provided to illustrate their use and flexibility.

Color Ramp: rainbow()

The rainbow() ramp is is the standard light spectrum with red, green and blue as its base. The functional form is rainbow(n, s=1, v=1, start=0, end=max(1, n-1)/n, alpha=1).  The s and v values correspond to saturation and value from the HCL color scheme (described below).  The parameters start and end can be used to specify particular subranges of hues. The following values can be used when generating such a subrange: red = 0, yellow = 1/6, green = 2/6, cyan = 3/6, blue = 4/6 and magenta =5/6.

Posted in R Colors, R Graphics | Leave a comment

R Graphics Gallery

An  R graphics gallery has been created with simple scripts for long-term reference and to expedite data visualization.

Bar Plot of Vector

plot3          Click to enlarge

Bar Plot of Matrix: #1

plot4          Click to enlarge

Bar Plot of Matrix: #2

plot5          Click to enlarge

Box Plot

plot6          Click to enlarge

Posted in R Graphics | Leave a comment

R Graphics: Plot Parameters

High level plot commands open a graphics device.  High level plot elements add objects.  R plot parameters ensure actual control over the graphics device.

R Plot Parameters

All high level plotting functions have arguments which can be used to customize the plot. barplot(), for example, has arguments to control bar width, styles, etc.  High level functions also take the optional “three dots” argument, which allows for argument sharing.  The most common arguments shared are low level graph parameters from the par() function.

Posted in R Graphics | Leave a comment

R Graphics: Heat Colors

Heat colors in R utilize basic color ramp  functions.  Simple example scripts with basic control options follow.

Heat Colors

The heat.colors() function creates a ramp of contiguous colors clustered around the color orange in the red spectrum of the RGB scale.  The function has the form heat.colors(num_colors, alpha=value).

Color Ramp Example

Plot117

Alpha Transparency

Heat color transparency is controlled with the optional alpha argument.  The default value is alpha=1.

Posted in R Colors, R Graphics | Leave a comment

R Graphics: Grey Scales

Grey scales in R can be used effectively in data visualization.  Several simple functions can be used to great effect.

Creating Gray Scales

The gray.colors() function creates a vector of interpolated values that represent evenly-spaced gray colors. 

The function has the form gray.colors(num_colors, start = value, end = value, gamma = value).  End and start define the endpoints of the range of grays, with 0 = black and 1 = white being the extreme values. (By default, start = 0.3 and end = 0.9.) gamma is an optional argument which controls luminance.

Posted in R Colors, R Graphics | Leave a comment

R Graphics: High Level Commands

High level commands and plotting functions in R set up a co-ordinate system.  No plotting is done inside a graphics device until at least one high level function has established the co-ordinate system.  High level commands include plot type and plot elements. Together, they provide users with direct control of all graph objects and support the creation of highly customized data visualizations.

Posted in R Graphics | Leave a comment

R Graphics: Multi-Graph Layouts

The layout() Function

The ability to manage multiple plots in one graphical device or window is a key capability to enhance data visualization and analysis.

The layout() function in base R is the most straightforward method to divide a graphical device into rows and columns.  The function requires an input matrix definition.  Column-widths and the row-heights can be defined using additional input arguments.  layout.show() can then be used to see multi-graph layouts and how the graphical device is being split.

Posted in R Graphics, R Programming | Leave a comment

Multiple Plots (ggplot)

The multiplot() Function

Winston Chang’s R Graphical Cookbook provides a useful function to simplify the creation of layouts with multiple plots.  The function accepts ggplot objects as inputs.

Use of the function is straightforward.  First, multiplot() needs to be sourced and available in memory.  Then the plots need to be coded with variable assignments to create plot objects.  Finally, multiplot() is used to call the plot objects for placement in the predefined plot layout.

Posted in ggplot2, R Graphics | Leave a comment

R Color Tables: Download Now

The following page provides R color tables by name and hexadecimal code. The tables can be downloaded for local reference or recreated with R code provided.

R Color Tables: By Name

A pdf file for the color name table can be downloaded here.

R color tablesClick to enlarge

R Color Tables: By Hex Code

A pdf file for the hex code table can be downloaded here.

R color tablesClick to enlarge

Posted in R Colors, R Graphics | 1 Comment

Color Palettes in R

The following list details all color palettes and color ramp functions in R.  Detailed color tables are created for long-term reference and to aide code scripting.  The objective is to simplify the delivery of publication quality graphics.

Next

Posted in R Colors, R Graphics | Leave a comment

R Graphics (base)

R graphics reference material is supplied on the high-level commands and the low level parameters that control full flexibility of R’s graphical environment.  Subchapters are organized as follows:

Structure and Devices
High-Level Commands
Example Plots
Graphics Parameters
Multi-graph Layouts
Trellis Charts

Back | Next

Posted in R Graphics | Leave a comment

Aerosol Animation

Aerosol Optical Depth (AOD) defines the degree to which aerosols prevent the transmission of sunlight by absorption or scattering.  AOD is measured using an integrated extinction coefficient over a vertical column of air.  The extinction coefficient can be used to analyze solar extinction and the performance of solar power systems as a function of location and time.

GOCART

Posted in Animation, Data, Dust, Meteorology, Modeling, Qatar RE, R Data Import, R Graphics, Resource Assessment, Saudi Arabia, Solar, Spatial Analysis | Leave a comment