library(readr)
library(dplyr)
library(magrittr)
ecom <- read_csv('https://raw.githubusercontent.com/rsquaredacademy/datasets/master/ecom.csv',
col_types = list(col_factor(levels = c('Desktop', 'Mobile', 'Tablet')),
col_factor(levels = c(TRUE, FALSE)), col_factor(levels = c(TRUE, FALSE)),
col_factor(levels = c('Affiliates', 'Direct', 'Display', 'Organic', 'Paid', 'Referral', 'Social'))))
## # A tibble: 5,000 x 4
## device bouncers purchase referrer
## <fctr> <fctr> <fctr> <fctr>
## 1 Desktop FALSE FALSE Affiliates
## 2 Mobile FALSE FALSE Affiliates
## 3 Desktop TRUE FALSE Organic
## 4 Desktop FALSE FALSE Organic
## 5 Mobile TRUE FALSE Direct
## 6 Desktop TRUE FALSE Direct
## 7 Desktop FALSE FALSE Referral
## 8 Tablet TRUE FALSE Organic
## 9 Mobile TRUE FALSE Social
## 10 Desktop TRUE FALSE Organic
## # ... with 4,990 more rows
Below is the description of the data set:
plot(ecom$device)
barplot(table(ecom$device))
device_freq <- table(ecom$device)
device_freq
##
## Desktop Mobile Tablet
## 3335 1484 181
barplot(device_freq, horiz = TRUE)
barplot(device_freq, names.arg = c('Desktop', 'Mobile', 'Tablet'))
barplot(device_freq, col = 'blue')
device_referrer <- table(ecom$device, ecom$referrer)
device_referrer
##
## Affiliates Direct Display Organic Paid Referral Social
## Desktop 100 463 89 1575 74 647 387
## Mobile 8 241 182 832 60 17 144
## Tablet 4 23 18 113 9 0 14
barplot(device_referrer)
barplot(device_referrer, col = c('blue', 'red', 'green'))
barplot(device_referrer, col = c('blue', 'red', 'green'),
main = 'Gears vs Cylinders', legend.text = TRUE,
xlab = 'Accquisition Channel', ylab = 'Visitors')
barplot(device_referrer, col = c('blue', 'red', 'green'), beside = TRUE,
legend.text = TRUE, main = 'Device Distribution by Referrer Type',
xlab = 'Accquisition Channel', ylab = 'Visitors')
barplot(device_freq, width = 2)
barplot(device_freq, space = c(1, 1, 2))
barplot(device_freq, border = 'blue')
barplot(device_freq, axes = FALSE)
barplot(device_freq, axis.lty = 3)
barplot(device_freq, offset = 10)
barplot(device_freq, ylim = c(0, 4000))
barplot(device_freq, col = c('blue', 'red', 'green'),
horiz = TRUE, width = c(1, 1, 2),
names.arg = c('Desktop', 'Mobile', 'Tablet'),
axis.lty = 2, offset = 10)
barplot(device_freq, col = c('blue', 'red', 'green'), axis.lty = 2,
width = c(2, 1, 0.5), names.arg = c('Desktop', 'Mobile', 'Tablet'), offset = 2)
title(main = 'Distribution of Devices',
ylab = 'Visitors', xlab = 'Device')