Problem

Adventure Works is online bicycle store which sales bicycle and accessories. They want to analyse to see if there are any relation of their products sales number and total sales amount against unit price of different types of product

Data comes in Excel file which from their admin system.

Import data : Excel Files

This vignette looks at how to import data from excel file and interect with data

Install following package

To load Excel files into R, we can use readxl

Simply run the following piece of code to Install package:

install.packages("readxl")

Readxl can be used to easily to read files

library(readxl)
Datafile <- read_excel("<name and extension of your file>")

Note that the first argument specifies the path to your .xls or .xlsx file, which you can set by using the getwd() and setwd() functions. You can also add a sheet argument

AW_Data <- read_excel("C:/Users/masud/OneDrive/Documents/R/Assaignment1/Bycyclesales.xlsx")

Analysis of data

We use ggplot2 as plotting system for this vignette.

Install following package

Simply run the following piece of code to Install package:

install.packages("ggplot2")

qplot (Quick Plot) function of ggplot2 can be used to easily plot data

Price-Qty Relationship for Product type Bike

library(ggplot2)
qplot(UnitPrice, TotalSaleQty, data=subset(AW_Data,ProductCatagory=="Bikes"), colour=ProductCatagory)+ggtitle("Price-Qty Relationship")

data=subset(AW_Data,ProductCatagory==“Bikes”) been used for data segmentation ggtitle(“Price-Qty Relationship”) Title for the graphs

Price-Qty Relationship for Other Product types (Not Bikes)

library(ggplot2)
qplot(UnitPrice, TotalSaleQty, data=subset(AW_Data,ProductCatagory!="Bikes"), colour=ProductCatagory)+ggtitle("Price-Qty Relationship")

Adding a smoother to a plot

Becasue we have lots of scatterplot it is hard to see exactly what trend is shown by this data. We can smoothed line to the plot. This is easily done using the smooth geom

library(ggplot2)
qplot(UnitPrice, TotalSaleQty, data=subset(AW_Data,ProductCatagory=="Bikes"), colour=ProductCatagory, geom = c("point", "smooth"))+ggtitle("Price-Qty Relationship")
## `geom_smooth()` using method = 'loess'

## `geom_smooth()` using method = 'loess'

Refernce

http://www.statmethods.net/advgraphs/ggplot2.html seen at 9th April 2017