forked from DoubleD1994/R_Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreatingDataVisualisations.R
52 lines (43 loc) · 1021 Bytes
/
CreatingDataVisualisations.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#Creating Data Visualisation
# Set the working directory
setwd("/Users/daviddryburgh/Documents/R_Programming")
# Read the CSV file
cars <- read.csv("Cars.csv")
# Load the ggplot2 library
library(ggplot2)
# Create a frequency bar chart
ggplot(
data = cars,
aes(x = Transmission)) +
geom_bar() +
ggtitle("Count of Cars by Transmission Type") +
xlab("Transmission Type") +
ylab("Count of Cars")
# Create a histogram
ggplot(
data = cars,
aes(x = Fuel.Economy)) +
geom_histogram(
bins = 10
) +
ggtitle("Distribution of Fuel Economy") +
xlab("Fuel Economy") +
ylab("Count of Cars")
# Create a density plot
ggplot(
data = cars,
aes(x = Fuel.Economy)) +
geom_density() +
ggtitle("Distribution of Fuel Economy") +
xlab("Fuel Economy (mpg)") +
ylab("Density")
# Create a scatterplot
ggplot(
data = cars,
aes(
x = Cylinders,
y = Fuel.Economy)) +
geom_point() +
ggtitle("Fuel Economy by Cylinders") +
xlab("Number of Cylinders") +
ylab("Fuel Economy (mpg)")