This dataset, extracted from the 1974 Motor Trend US magazine, includes fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models).
In this dataset, variables are categorized as either categorical or quantitative:
cyl (Number of cylinders)vs (Engine: 0 = V-shaped, 1 = straight)am (Transmission type: 0 = automatic, 1 = manual)gear (Number of forward gears)carb (Number of carburetors)mpg (Miles per gallon)disp (Displacement in cubic inches)hp (Gross horsepower)drat (Rear axle ratio)wt (Weight in 1000 lbs)qsec (1/4 mile time)The following sections demonstrate different ways to visualize data distributions and relationships between variables.
## mpg cyl disp hp drat wt qsec vs am gear carb
## Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
## Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
## Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
## Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
## Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
## Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
A bar chart is a useful way to show the frequency of
each category in a categorical variable, such as the number of cylinders
(cyl) in this dataset. Each bar represents the count of
cars for a given cylinder count.
A pie chart is another way to represent the relative proportions of each category. Here, we can see the distribution of cars based on their cylinder counts as slices of a pie.
To understand the distribution of a quantitative variable like mpg, we use the following plots:
This shows how frequently different ranges of MPG values appear.Each bar represents a range of values, providing insight into the spread and shape of the data.
## Stemplot of MPG:
##
## The decimal point is at the |
##
## 10 | 44
## 12 | 3
## 14 | 3702258
## 16 | 438
## 18 | 17227
## 20 | 00445
## 22 | 88
## 24 | 4
## 26 | 03
## 28 |
## 30 | 44
## 32 | 49
To explore the relationship between two categorical variables,
cyl and am, we can use side-by-side and
stacked bar charts. These show how each transmission type is distributed
across different cylinder counts.
##
## Automatic Manual
## 4 3 8
## 6 4 3
## 8 12 2
A scatterplot is ideal for visualizing the relationship between two quantitative variables, such as hp (horsepower) and mpg. Each point represents a car, with its hp on the x-axis and mpg on the y-axis, helping us see if there’s any trend.
Adding a trend line to the scatterplot helps visualize any linear relationship between hp and mpg. Here, we add a regression line to see how mpg changes as hp increases.