Based Plot: Bar Plot
Summary of R Commands Used
1. barplot()
: Creates bar plots (vertical, horizontal, grouped, stacked).
2. table()
Creates a frequency table (counts).
Works with vectors, factors, or data frames.
Can be combined with
t()
(transpose) to flip rows and columns.
3. t()
Transposes a table or matrix.
Used with
table()
before plotting → changes grouping orientation.
4. sort()
Orders numeric or factor levels before plotting.
Example:
table(faculty) |> sort()
5. Pipe Operator (|>
)
Passes results from one function to the next.
Example:
|> table() |> barplot() faculty
6. box()
Adds a box (frame) around an existing plot.
Argument
col
changes the box color.