#================================================================================================================#
#========== Jacek Wallusch ==========#
#========== APPLIED QUANTITATIVE METHODS FOR BUSINESS DEVELOPMENT AND ANALYSIS ==========#
#========== Lecture 4: Multidimensional Graphs ==========#
#================================================================================================================#
# Data: Used car prices
# Data courtesy: Allegro, Audi Q5 (filters: accident-free, Diesel engine, drivetrain full-time AWD,
# registered in Poland, undamaged, available for auction on October 2016
# Libraries: plotly
library(plotly)
#-----------------------------------------------------------------------------------------------------------------
# IMPORT THE DATA in .csv-format (change the location of your file!):
audiq5 <- read.csv("C:/Users/SESA387551/Documents/Lehre/Wintersemester-2016/audiq5.csv", header=TRUE, sep = ";")
q5_year <- audiq5[,1]
q5_encc <- audiq5[,2]
q5_mila <- audiq5[,3]
q5_pric <- audiq5[,4]
q5_ccde <- audiq5[,5]
# merge the engine capacity and last column
q5_ccdu <- paste(q5_encc, q5_ccde, sep = "")
#-----------------------------------------------------------------------------------------------------------------
# Scatter plot with size
plot_ly(x = q5_mila, y = q5_pric,
size = q5_year, # define size variable
sizes = c(50,200), # define size (min = 50, max = 200)
type = "scatter", mode = "markers")%>%
layout(title = "Audi Q5: Milage and Price",
xaxis = list(title = "Milage in km"),
yaxis = list(title = "Price in PLN"))
#-----------------------------------------------------------------------------------------------------------------
# Scatter plot with size and colour
plot_ly(x = q5_mila, y = q5_pric,
size = q5_year, # define size variable
sizes = c(50,200), # define size (min = 50, max = 200)
color = q5_ccdu, # define colour variable
colors = c("dark green", "dark red"), # define colours
type = "scatter", mode = "markers")%>%
layout(title = "Audi Q5: Milage and Price",
xaxis = list(title = "Milage in km"),
yaxis = list(title = "Price in PLN"))
#-----------------------------------------------------------------------------------------------------------------
# 3D-Scatter plot with colour
plot_ly(x = q5_mila, y = q5_ccdu, z = q5_pric, name = "Audi Q5",
type = "scatter3d", # define type as scatter3d
mode = "markers",
color = q5_year, # define colour variable
marker = list(colorbar = list(title = "Year of built")))%>%
layout(title = "Audi Q5: Milage and Price",
scene = list(xaxis = list(title = "Milage"),
yaxis = list(title = "Eng. Capacity"),
zaxis = list(title = "Price")),
margin = list(l = 150, r = 150, b = 150, t = 150, pad = 1))