SlideShare a Scribd company logo
Uber_Trips_Visualizations.R
aymansiraj
Mon Aug 15 10:28:32 2016
# load required packages
suppressMessages(library(ggplot2))
suppressMessages(library(data.table))
suppressMessages(library(lubridate))
suppressMessages(library(scales))
suppressMessages(library(stringr))
suppressMessages(library(zoo))
suppressMessages(library(dplyr))
# load file and clean
setwd("/Users/aymansiraj/Google Drive/ix 2016 /RUber")
Uber <- read.csv("trip-history.csv")
Uber$trip_id <- NULL
Uber$date_time <- NULL
Uber$driver <- NULL
Uber$payment_method <- NULL
Uber$start_address <- NULL
Uber$end_address <- NULL
Uber <- Uber %>% subset(price != "")
# format data types currently
Uber$date <- as.character(Uber$date)
Uber$datenew <- parse_date_time(Uber$date, c('mdy'))
Uber$Month <- months(Uber$datenew)
Uber$Year <- year(Uber$datenew)
# create new columns to plot graphs
Uber$MonthYear = as.factor(paste(Uber$Month, Uber$Year, sep="-"))
Uber$currency<- as.factor(gsub("[0-9.]","", Uber$price))
Uber$pricenew <- as.numeric(gsub("[^0-9.]","", Uber$price))
# calculate amount spent on each currency
costpercurrency <- Uber %>%
group_by(currency) %>%
summarise(TotalCost = sum(pricenew))
# ggplot
city <- qplot(city, data=Uber, geom="bar", fill= car_type)
city + theme(axis.text.x = element_text(angle = 90, hjust = 1))
cartype <- qplot(car_type, data = Uber, geom = "bar", fill = city)
cartype + theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplot(Uber, aes(MonthYear)) + geom_bar() +
geom_text(stat='count',aes(label=..count..),vjust=-1) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
costplot <- ggplot(costpercurrency, aes(x=currency, y=TotalCost)) +
geom_bar(stat="identity", fill="#FF9999", colour="black")
costplot + geom_text(aes(label=TotalCost), vjust=1.6, color="white",
size=3.5)
Uber_Trips_Visualizations

More Related Content

ZIP
Web+GISという視点から見たGISの方向性
PPTX
5. chapter iv
PDF
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
PDF
Plone Conference 2008 Lightning Talk Static Zope Rpx
ODP
JQuery introduction
PDF
YAPC::Asia 2010 Twitter解析サービス
PDF
LINE iOS開発で実践しているGit tips
PDF
Blog Hacks 2011
Web+GISという視点から見たGISの方向性
5. chapter iv
Absolute Beginners Guide to Puppet Through Types - PuppetConf 2014
Plone Conference 2008 Lightning Talk Static Zope Rpx
JQuery introduction
YAPC::Asia 2010 Twitter解析サービス
LINE iOS開発で実践しているGit tips
Blog Hacks 2011

What's hot (20)

ODP
FRP and Bacon.js
PDF
Wat.tf - Nati Cohen - DevOpsDays Tel Aviv 2018
PDF
A Self Replicating Serverless Function
PDF
Starting out with Ember.js
PDF
Twib in Yokoahma.pm 2010/3/5
PDF
WordPress 次期バージョンと日本のコミュニティ
PDF
global_shopping_online
PDF
global_shopping_online
PDF
global_shopping_online
PDF
global_shopping_online
PDF
global_shopping_online
XLS
Up.Php
PDF
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
PDF
Desymfony 2011 - Habemus Bundles
PDF
PPTX
Mongo db modifiers
PDF
Climbing out from the digital mud with unikernels / Ian Eyberg (DeferPanic)
PDF
Iron Blogger Hamburg #bchh13
KEY
Java & Script ─ 清羽
KEY
Java&Script
FRP and Bacon.js
Wat.tf - Nati Cohen - DevOpsDays Tel Aviv 2018
A Self Replicating Serverless Function
Starting out with Ember.js
Twib in Yokoahma.pm 2010/3/5
WordPress 次期バージョンと日本のコミュニティ
global_shopping_online
global_shopping_online
global_shopping_online
global_shopping_online
global_shopping_online
Up.Php
第4回 g* ワークショップ はじめてみよう! Grailsプラグイン
Desymfony 2011 - Habemus Bundles
Mongo db modifiers
Climbing out from the digital mud with unikernels / Ian Eyberg (DeferPanic)
Iron Blogger Hamburg #bchh13
Java & Script ─ 清羽
Java&Script
Ad

Similar to Uber_Trips_Visualizations (20)

PDF
PPTX
Using R for Building a Simple and Effective Dashboard
PDF
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
PDF
Юрий Буянов «Squeryl — ORM с человеческим лицом»
PPTX
API Development and Scala @ SoundCloud
PDF
Bag Of Tricks From Iusethis
DOCX
R (Shiny Package) - Server Side Code for Decision Support System
PDF
Memory Manglement in Raku
PPT
JQuery Flot
PDF
Postman On Steroids
PDF
The never changing face of immutability
PDF
Kafka Streams: Revisiting the decisions of the past (How I could have made it...
PDF
mongoDB @ banksalad
PDF
I really need help with this assignment it is multiple parts# Part.pdf
PDF
Failsafe Mechanism for Yahoo Homepage
PDF
Automation in angular js
PDF
dplyr use case
PPTX
OpenStreetMap R
PDF
Velocity tips and tricks
PDF
Large Scale Data Processing & Storage
Using R for Building a Simple and Effective Dashboard
Spark + Clojure for Topic Discovery - Zalando Tech Clojure/Conj Talk
Юрий Буянов «Squeryl — ORM с человеческим лицом»
API Development and Scala @ SoundCloud
Bag Of Tricks From Iusethis
R (Shiny Package) - Server Side Code for Decision Support System
Memory Manglement in Raku
JQuery Flot
Postman On Steroids
The never changing face of immutability
Kafka Streams: Revisiting the decisions of the past (How I could have made it...
mongoDB @ banksalad
I really need help with this assignment it is multiple parts# Part.pdf
Failsafe Mechanism for Yahoo Homepage
Automation in angular js
dplyr use case
OpenStreetMap R
Velocity tips and tricks
Large Scale Data Processing & Storage
Ad

Uber_Trips_Visualizations

  • 1. Uber_Trips_Visualizations.R aymansiraj Mon Aug 15 10:28:32 2016 # load required packages suppressMessages(library(ggplot2)) suppressMessages(library(data.table)) suppressMessages(library(lubridate)) suppressMessages(library(scales)) suppressMessages(library(stringr)) suppressMessages(library(zoo)) suppressMessages(library(dplyr)) # load file and clean setwd("/Users/aymansiraj/Google Drive/ix 2016 /RUber") Uber <- read.csv("trip-history.csv") Uber$trip_id <- NULL Uber$date_time <- NULL Uber$driver <- NULL Uber$payment_method <- NULL Uber$start_address <- NULL Uber$end_address <- NULL Uber <- Uber %>% subset(price != "") # format data types currently Uber$date <- as.character(Uber$date) Uber$datenew <- parse_date_time(Uber$date, c('mdy')) Uber$Month <- months(Uber$datenew) Uber$Year <- year(Uber$datenew) # create new columns to plot graphs Uber$MonthYear = as.factor(paste(Uber$Month, Uber$Year, sep="-")) Uber$currency<- as.factor(gsub("[0-9.]","", Uber$price)) Uber$pricenew <- as.numeric(gsub("[^0-9.]","", Uber$price)) # calculate amount spent on each currency costpercurrency <- Uber %>% group_by(currency) %>% summarise(TotalCost = sum(pricenew))
  • 2. # ggplot city <- qplot(city, data=Uber, geom="bar", fill= car_type) city + theme(axis.text.x = element_text(angle = 90, hjust = 1)) cartype <- qplot(car_type, data = Uber, geom = "bar", fill = city) cartype + theme(axis.text.x = element_text(angle = 90, hjust = 1))
  • 3. ggplot(Uber, aes(MonthYear)) + geom_bar() + geom_text(stat='count',aes(label=..count..),vjust=-1) + theme(axis.text.x = element_text(angle = 90, hjust = 1))
  • 4. costplot <- ggplot(costpercurrency, aes(x=currency, y=TotalCost)) + geom_bar(stat="identity", fill="#FF9999", colour="black") costplot + geom_text(aes(label=TotalCost), vjust=1.6, color="white", size=3.5)