Sunday, August 23, 2020

plot (Index plot)

This is a two dimensional plot where the index (such as time) is the x variable, and the measured value is the y variable. Use an index plot when you want to plot ordered data against an increasing scale. Kern assumes that the increasing scale will be time.

You can use the generic plot function to create a index plot (the RcmdrMisc.indexplot is also available). The plot function offers 9 ways to display the data, from points to steps.

R Example

This example shows the changes in the depth of Lake Huron from 1875 to 1972, using a single line ("l") display.

plot(LakeHuron, type = "l")

graph of Lake Huron depths

Reference

Thursday, August 20, 2020

hist

Create a histogram. The hist function is in the base R package. With hist, the only param you need (out of about 20) is a data frame.

There are other histogram functions available from other packages (lattice.histogram, for example). Regardless of which you choose, the advantages and disadvantages are the same.

Use a histogram when you want to view the frequency of occurrence of something across a set of sequential bins. Another way of saying it is a histogram shows a distribution of a variable. Silt depth from shore to 3', from 3' to 6', 6' to 9', and so on. It is distinguished from a bar graph, which is used to compare one or more variables.

Histogram Weakness

You must take care determining the bin size for your histogram. A bin size that is less than optimal can provide a misleading depiction. With hist, experiment with the breaks parameter to adjust the graph for the best information display for your purposes.

R Example

This example shows precipitation for each of 70 U.S. + Puerto Rico cites.

hist(precip, breaks = 25)
histogram of precip in US cities

The breaks parameter directs histogram is to have 25 bins (note that if you count the bins, you don't get 25 -- I'm thinking that R adjusts it +/- from the value of breaks for a better result). Anyway, 4 cities had rainfall between 0-5 inches, and one city had rainfall over 65 inches.

You can have hist show frequency or relative probability. It just changes the left hand scale.

Monday, August 17, 2020

stripchart (dot plot)

Also known as strip chart and strip plot. Call this function in the form:

stripchart(quantity ~ category, method = "stack", data = "data.frame")

stripchart produces a one-dimensional scatter plot on discrete, continuous, and univariate data. Data points are plotted above a single numeric scale. You can create dot plots by hand. Use them when the data set is small, and you want to identify outliers and clusters of values.

While the only required parameter for stripchart is the data frame, optional parameters let you set horizonal or vertical orientation, group data in categories, and add "jitter", to help keep values from superimposing.

R Example

This example plots the values from the standand rivers dataset, the lengths of 141 major rivers in North America.

stripchart(rivers, method = "jitter", xlab = "length")
dot plot of rivers dataset