Skip to content

Instantly share code, notes, and snippets.

@juananpe
Created December 18, 2017 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juananpe/828a4a0f3db57b38ad405fb9a000fc8e to your computer and use it in GitHub Desktop.
Save juananpe/828a4a0f3db57b38ad405fb9a000fc8e to your computer and use it in GitHub Desktop.
linearReg.R
library(ggplot2)
# Price, Age, KM(kilometers driven), Fuel Type,
# HP(horsepower), Automatic or Manual, Number of Doors,
# and Weight in pounds are the data collected in this file for
# Toyota Corollas.
toyota <- read.csv("https://raw.githubusercontent.com/datailluminations/PredictingToyotaPricesBlog/master/ToyotaCorolla.csv")
g <- ggplot(toyota, aes(Price))
g <- g + geom_histogram(
# binwidth = 25,
bins = 30,
col="black",
size=.1) +
labs(
y="Count",
x="Price",
caption = "Source: Toyota")
plot(g)
head(toyota)
sapply(toyota, class)
summary(toyota$FuelType)
# Price vs Age
ggplot(toyota,aes(x=Age,y=Price))+
geom_point() +
# geom_smooth(method="loess", se=T) +
labs(
y="Price",
x="Age",
caption = "Source: toyota")
# Price vs KM
ggplot(toyota,aes(x=KM,y=Price))+
geom_point() +
# geom_smooth(method="loess", se=T) +
labs(
y="Price",
x="KM",
caption = "Source: toyota")
# Price vs Metalizado (factor)
ggplot(toyota, aes(x=MetColor, y=Price,color=factor(MetColor))) +
geom_point(shape=1)
# Price vs HorsePower
ggplot(toyota, aes(x=HP, y=Price)) +
geom_point(shape=1)
# Price vs Doors
ggplot(toyota, aes(x=Doors, y=Price)) +
geom_point(shape=1)
linReg <- lm(formula = Price ~ ., data = toyota)
summary(linReg)
corAgePrice <- cor(toyota$Age, toyota$Price)
corAgePrice
cors <- cor(subset(toyota, select = c(Price, Age, KM, HP, Weight)))
class(cors)
library(ggcorrplot)
# Plot
ggcorrplot(cors, hc.order = TRUE,
type = "lower",
lab = TRUE,
lab_size = 3,
method="circle",
colors = c("tomato2", "white", "springgreen3"),
title="Correlogram of toyota",
ggtheme=theme_bw)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment