Your First Plot in R

Interactive R tutorial on plotting: draw histograms, scatter plots and boxplots live in your browser with base R graphics โ€” edit the code and see the figure change.

R makes graphs with a single line. Every plot below draws in your browser โ€” Run each box, then tweak it.

A histogram

Histograms show the shape of a single variable:

Change col to another colour name (like "tomato") and run it again.

A scatter plot

Scatter plots show the relationship between two variables:

Heavier cars (right) get fewer miles per gallon (down) โ€” a clear negative relationship.

Add a trend line

lm() fits a straight line; abline() draws it. You just made your first regression plot.

A boxplot by group

Boxplots compare groups at a glance โ€” more cylinders, lower mpg. (How to read a boxplot.)

Your turn


Next: Basic statistics โ†’ โ€” from pictures to numbers.