The key tasks carried out in the ggplot2 workshop are presented below.
Step1: the data was imported
Step2: A scatterplot to see the relationship between amount and age was done
# import data
Blackwell_Hist_Sample2 <- read.delim(file = "C:/Users/gebruiker/Desktop/Ubiqum_1/Blackwell_Hist_Sample.csv", sep = ",",header = T,nrows = 10000)
Blackwell_Hist_Sample3 <- readRDS(file = "C:/Users/gebruiker/Downloads/Blackwell_Hist_Sample.rds")
library(ggplot2)
ggplot(data = Blackwell_Hist_Sample3) +
geom_point(aes(x = amount, y = age))
Step3: Different scatter plots for each region was then created using the facet function
ggplot(data = Blackwell_Hist_Sample3,
aes(x = amount, y = age)) +
geom_point() +
facet_wrap(. ~ region)
Step4: the trend between amount and age was then created, using facet function and delineating based on instore and online purchase
ggplot(data = Blackwell_Hist_Sample3, aes(x = age, y = amount, color = region)) + geom_point() + geom_smooth() + facet_wrap(region ~ in.store)
## `geom_smooth()` using method = 'gam' and formula 'y ~ s(x, bs = "cs")'
Step4 A barchart showing the count in each of the four regions was done.
ggplot(data = Blackwell_Hist_Sample3, aes(region))+
geom_histogram(stat = "count")
## Warning: Ignoring unknown parameters: binwidth, bins, pad
#plot showing age vs salary with the colur based on brand
ggplot(data = Blackwell_Hist_Sample3,
aes(x = amount, y = age, color = region)) + geom_point(position = "fill")