spread and distribution
This is more difficult than it may seem.
Read in the data cards.csv.
Time1 values for the Card == "D" subset.breaks = ... to set the number of “bars”.Layer on data from any other card (A-C) by using add = T and specifying a color.
What do you notice about the rendering of the histograms? Are you satisfied?
In general, this makes more than a couple histograms very difficult to read and interpret.
It is recommended that you use filled density plots to compare multiple distributions.
More on that later.
In general, there is no “right number” of “bins” (or “cells”) to display.
This takes experimentation. Which below is “best”? What might help you decide?
This takes experimentation. Which below is “best”?
The breaks = ... is quite flexible, but works in occasionally mysterious ways.
One argument breaks = n passes that number to an underlying function and asks for n + 1 points that delimit n bins.
One nice options is to define equally-spaced ranges using the colon operator or seq(from = ..., to = ..., length = ...).
breaksUsing any subset of the card data, experiment with various ways of implementing breaks discussed previously.
Comment on what this “tells you” about the data or how it might help you “tell others”!
A great deal of statistical practice is related to assumptions of “normality”.
Histograms are a classic tool for the visual assessment of normality and can give evidence of other properties.
Use the code below to generate 100 sampled values from a normal distribution with mean \(\mu = 2\) and standard deviation \(\sigma = 1\).
Then, add a histogram. Finally, repeat the sampling process and histogram visualization.
Generate the following data and make a histogram.
Now, make separate histograms of log10(rn) and log(rn).
What if anything do you notice?
It really doesn’t matter which logarithm you use in transformation, each has merits.
Label your axis carefully.
Today is the 35th day of 2025. Notice \(\ln(35) \approx 3.555\), and \(\log(35) \approx 1.544\).
These mean that \(e^{3.555} \approx 35\) and \(10^{1.544} \approx 35\).
One implication is that if we report “log”-transformed data, we need to be specific about which base.
Using a base-10 logarithm, transform the “lognormal” data and generate a histogram.
What has changed?
Separately, generate random values and histograms for shape = 1/2, 1, 2.
Try to assess the role of shape.
A common visual “test” of data properties is to overlay a density upon its histogram.
As mentioned, it is “best” to layer filled-density plots, rather than histograms.
That said, just like hist() has a variety of defaults choices, so does density().
Experiment with density(..., bw = ...) by choosing values for the “bandwidth”. Use your experiments to learn about what this argument does.
cols <- hcl.colors(5, alpha = 0.5)
plot(density(dat[dat$Card=="A", "Time1"], from = 0, to = 10, na.rm = T,
bw = 1/2), col = cols[1], lwd = 2, ylim = c(0, 1))
for(i in 1:5){
den <- density(dat[dat$Card==LETTERS[i], "Time1"], from = 0, to = 10,
na.rm = T, bw = 1/2)
polygon(c(den$x, rev(den$x)), c(0*den$y, rev(den$y)), col = cols[i], lwd = 2)
}Have we made it?
To be clear, tables are a form of data visualization.
These are someone analagous to MS Excel “Pivot Tables”.
Within “base R”, personal favorites are table() and aggregate().
It is often useful to assign these tables to a temporary variable such as tab or tmp.
Alternate “model” syntax is possible!
We can use a related command merge() to combine multiple aggregated values and names() to give it some organization.
Recall the “preattentive pop-out” data stored in cards.csv.
What vizualizations are relevant?
A basic boxplot, as we’ve seen, comes pretty quickly.
What does it mean?
It might help to know what in our data is reflected in the plot.
For simplicity we will switch to a built-in dataset, warpbreaks. Use ?warpbreaks to view its description and citation.
Roughly, it contains columns
breaks the number of breaks per length of yarnwool the type of wool (A or B)tension the weaving tension (L, M, H)Notice that the order of specifying the variables matters!
We could experiment with
There are some interesting features that emerge.
“Recently” boxplots (circa 1977) have evolved into violin plots (circa 1997).
More simply, boxplots can be overplotted with dots.
Since many of the dots might overlap, we might be interested in incorporating horizontal jitter to alter the readability
Things get a little slippery here.
tension and wool are categorical, so it might take a bit of scratchwork to determine sensible, numerical input values.