Your First Plot in R
R makes graphs with a single line. Every plot below draws in your browser β Run each box, then tweak it.
Watch: your first plots in one minute
Watch each graph β a histogram, a scatter plot, a trend line and a boxplot β drawn live in RStudio, then recreate them in the consoles below.
Download the R script Β· βΆ Practice in the playground β or edit and run each snippet below.
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.