Strip Charts in R
Strip Charts in R
Introduction
A strip chart (also called a dot plot) is a simple graphical technique used to display individual observations of a dataset. Each data value is represented by a dot placed along an axis.
Strip charts are particularly useful for:
- Small datasets.
- Visualizing the distribution of data.
- Comparing groups.
- Detecting clusters and outliers.
- Displaying individual observations without grouping them into bins.
Unlike histograms, strip charts display every data point, making them ideal when the number of observations is relatively small.
Syntax
stripchart(x,
method,
pch,
col,
main,
xlab,
ylab,
vertical)
where
- x : vector or formula.
- method : arrangement of points.
- pch : plotting symbol.
- col : color.
- main : title.
- xlab : x-axis label.
- ylab : y-axis label.
- vertical : vertical or horizontal display.
Example 1: Simple Strip Chart
Suppose marks of students are
marks <- c(45,50,55,60,65,70,75,80,85,90)
stripchart(marks)
Output:
Dots are plotted horizontally.
Example 2: Add Title and Labels
Example 3: Change Plotting Symbol
stripchart(marks,
pch=19)
Common Values of pch
| pch | Symbol |
|---|---|
| 1 | Circle |
| 2 | Triangle |
| 3 | Plus |
| 15 | Square |
| 16 | Filled Circle |
| 17 | Filled Triangle |
| 18 | Diamond |
| 19 | Solid Circle |
Example:
stripchart(marks,
pch=18)
Example 4: Change Color
Example 5: Vertical Strip Chart
stripchart(marks,
vertical=TRUE,
pch=19,
col="red")
This displays the data vertically.
Example 6: Stack Method
Suppose data contain repeated values:
marks <- c(60,65,65,70,70,70,75,80,80,85)
stripchart(marks,
method="stack",
pch=19,
col="blue")
Here identical values are stacked.
Example 7: Jitter Method
stripchart(marks,
method="jitter",
pch=19,
col="green")
The points are slightly displaced to avoid overlap.
Example 8: Overplot Method
stripchart(marks,
method="overplot",
pch=19)
Repeated values overlap.
Example 9: Student Heights
Example 10: Comparing Two Groups
male <- c(165,170,172,175,180)
female <- c(155,160,162,165,168)
stripchart(list(Male=male,
Female=female),
pch=19,
col=c("blue","red"),
method="jitter")
This creates two strip charts side by side.
Example 11: Using Formula Interface
marks <- c(80,85,75,90,70,
88,95,78,65,72)
gender <- factor(c("Male","Male","Male","Male","Male",
"Female","Female","Female","Female","Female"))
stripchart(marks~gender,
method="jitter",
pch=19,
col=c("blue","pink"))
The notation
marks ~ gender
means:
Plot marks grouped by gender.
Example 12: Using Data Frames
Example 13: Multiple Departments
Example 14: Strip Chart with Box Plot
marks <- c(45,50,55,60,65,70,75,80,85,90)
boxplot(marks,
horizontal=TRUE)
stripchart(marks,
method="jitter",
pch=19,
col="red",
add=TRUE)
This overlays individual observations on the box plot.
Example 15: Random Data
Methods Available
| Method | Description |
|---|---|
"overplot" | Points overlap |
"stack" | Repeated values stacked |
"jitter" | Points randomly displaced |
Important Parameters
| Parameter | Purpose |
|---|---|
method | Arrangement of points |
pch | Plotting symbol |
col | Color |
main | Title |
xlab | X-axis label |
ylab | Y-axis label |
vertical | Vertical plot |
add | Add to existing graph |
Applications
- Displaying individual observations.
- Comparing groups.
- Detecting outliers.
- Supplementing box plots.
- Small sample data analysis.
- Exploratory Data Analysis (EDA).
Difference Between Strip Chart and Histogram
| Strip Chart | Histogram |
|---|---|
| Shows every observation | Shows frequencies |
| Suitable for small datasets | Suitable for large datasets |
| Uses dots | Uses bars |
| No binning required | Requires bins |
Created using stripchart() | Created using hist() |
Difference Between Strip Chart and Box Plot
| Strip Chart | Box Plot |
|---|---|
| Shows all observations | Shows summary statistics |
| Individual values visible | Values summarized by quartiles |
| Better for small datasets | Better for comparing distributions |
| Uses dots | Uses box and whiskers |
Summary of Useful Functions
| Function | Purpose |
|---|---|
stripchart() | Create strip chart |
boxplot() | Create box plot |
jitter() | Random displacement |
list() | Multiple groups |
factor() | Grouping variable |
rainbow() | Generate colors |
Conclusion
A strip chart is a one-dimensional scatter plot used to display individual data values. It is especially useful for small datasets and for visualizing the distribution and spread of observations. In R, the stripchart() function provides various methods such as overplot, stack, and jitter, making it an effective tool for exploratory data analysis and comparison of groups.
Comments
Post a Comment