Cars

We have the dataset of cars available in India, lets compare prices, specs, fuel economy etc. across car types.

Does better mileage means lower price?

What are the features that drive the mileage of cars?


In [ ]:
library(ggplot2)
library(dplyr)
library(tidyr)

In [ ]:
options(repr.plot.width = 10, repr.plot.height = 6)

Read CSV


In [ ]:
df <- read.csv("data/cars.tidy.csv", stringsAsFactor = FALSE)
df$price_in_1000 = df$price / 1000
colnames(df)

Filter all cars above 17 lakhs


In [ ]:
df <- filter(df, price < 1700000)

In [ ]:
head(df, 3)

In [ ]:
length(unique(df$name))

In [ ]:
str(df)

Single variable visualization

Engine Capacity


In [ ]:
ggplot(df, aes(engine)) + geom_histogram(binwidth = 300)

Seating Capacity


In [ ]:
ggplot(df, aes(seats)) + geom_bar(stat = "count")

In [ ]:
unique(df$type)

In [ ]:
colnames(df)

Multi variable visualization

Mileage in city vs Engine capacity


In [ ]:
ggplot(df,
 aes(mileage_city, engine, color=fuel)) + geom_point()

Visualize the mileage of petrol cars


In [ ]:
ggplot(filter(df, fuel == ' Petrol'),
 aes(mileage_highway, engine, color=fuel)) + geom_point()

Mileage vs Price vs Engine capacity


In [ ]:
ggplot(df,
 aes(mileage_city, price_in_1000, color=engine)) + geom_point() + ylim(c(0,1500))

Price vs Mileage


In [ ]:
ggplot(df, aes(price, mileage_city)) + geom_point()

In [ ]: