Stripchart R | R Strip Chart using stripchart() function - r - learn r - r programming
- Strip charts can be created using the stripchart() function in R programming language.
- This function takes in a numeric vector or a list of numeric vectors, drawing a strip chart for each vector.
r programming strip chart
Example 1: Strip chart of daily air quality
- Let us make a strip chart for the ozone readings.
- We can see that the data is mostly cluttered below 50 with one falling outside 150.
- We can pass in additional parameters to control the way our plot looks.
- You can read about them in the help section ?stripchart.
- Some of the frequently used ones are, main-to give the title, xlab and ylab-to provide labels for the axes, method-to specify the way coincident points are plotted like stacked or jitter, col-to define color etc.
- Additionally, with the argument vertical=TRUE we can plot it vertically and with pch we can specify the plotting character (square by default).
- Some values of pch are 0 for square, 1 for circle, 2 for triangle etc.
- You can see the full list in the help section
?points
.
Example 2: Strip chart of airquality using jitter
Multiple Strip Charts
- We can draw multiple strip charts in a single plot, by passing in a list of numeric vectors.
- Let us consider the Temp field of airquality dataset.
- Let us also generate normal distribution with the same mean and standard deviation and plot them side by side for comparison.
- Now we us make 2 stripcharts with this list.
Strip Chart from Formula
- The function stripchart() can also take in formulas of the form y~x where, y is a numeric vector which is grouped according to the value of x.
- For example, in our dataset airquality, the Temp can be our numeric vector.
- Month can be our grouping variable, so that we get the strip chart for each month separately.
- In our dataset, month is in the form of number (1=January, 2-Febuary and so on).