Realizar graficas del dataset de bicicletas
setwd("/Users/Mrm/Developer/R/Econometria I/Class 2")
bike_df <- read.csv("laboratorio1/hour.csv" , stringsAsFactors = FALSE , strip.white = TRUE , header = TRUE )
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
str(bike_df)
## 'data.frame': 17379 obs. of 17 variables:
## $ instant : int 1 2 3 4 5 6 7 8 9 10 ...
## $ dteday : chr "2011-01-01" "2011-01-01" "2011-01-01" "2011-01-01" ...
## $ season : int 1 1 1 1 1 1 1 1 1 1 ...
## $ yr : int 0 0 0 0 0 0 0 0 0 0 ...
## $ mnth : int 1 1 1 1 1 1 1 1 1 1 ...
## $ hr : int 0 1 2 3 4 5 6 7 8 9 ...
## $ holiday : int 0 0 0 0 0 0 0 0 0 0 ...
## $ weekday : int 6 6 6 6 6 6 6 6 6 6 ...
## $ workingday: int 0 0 0 0 0 0 0 0 0 0 ...
## $ weathersit: int 1 1 1 1 1 2 1 1 1 1 ...
## $ temp : num 0.24 0.22 0.22 0.24 0.24 0.24 0.22 0.2 0.24 0.32 ...
## $ atemp : num 0.288 0.273 0.273 0.288 0.288 ...
## $ hum : num 0.81 0.8 0.8 0.75 0.75 0.75 0.8 0.86 0.75 0.76 ...
## $ windspeed : num 0 0 0 0 0 0.0896 0 0 0 0 ...
## $ casual : int 3 8 5 3 0 0 2 1 1 8 ...
## $ registered: int 13 32 27 10 1 1 0 2 7 6 ...
## $ cnt : int 16 40 32 13 1 1 2 3 8 14 ...
demanda_por_temporada <- bike_df %>% group_by(season) %>% summarise(demando = sum(cnt))
barplot(demanda_por_temporada$demando , main="Demanda por temporada", xlab="Temporada",
ylab="Total", names.arg=c("Spring","Summer","Fall","Winter"), col=rainbow(4))
demanda_por_dia <- bike_df %>% group_by(holiday) %>% summarise(demando = sum(cnt))
barplot(demanda_por_dia$demando , main="Demanda por festivo", xlab="Dia",
ylab="Total", names.arg=c("No Festivo","Festivo"), col=rainbow(2))
anio_0 <- bike_df %>% filter( yr == 0 ) %>% group_by(mnth) %>% summarise(n=sum(cnt))
anio_1 <- bike_df %>% filter( yr == 1 ) %>% group_by(mnth) %>% summarise(n=sum(cnt))
range <- range( 0, anio_0$n , anio_1$n)
plot(anio_0$n, type="o", col="blue", ylim=range, xlim=c(1,12),xaxt='n', ann = FALSE)
axis(1, at=1:12, lab=c("Enero","Febrero","Marzo","Abril","Mayo","Junio","Julio","Agosto",
"Septiembre","Octubre","Noviembre","Diciembre"))
lines(anio_1, type="o", pch=22, lty=2, col="red")
title(main="Demanda por anio y mes", col.main="blue", font.main=4)
legend("topright", pch = 21:22, col = c("blue", "red"), legend = c("Anio 0", "Anio 1"))
anio_0 <- bike_df %>% filter( yr == 0 ) %>% group_by(weekday) %>% summarise(n=sum(cnt))
anio_1 <- bike_df %>% filter( yr == 1 ) %>% group_by(weekday) %>% summarise(n=sum(cnt))
range <- range( 0, anio_0$n , anio_1$n)
plot(x =anio_0$weekday, y = anio_0$n, type="o", col="blue", ylim=range, xlim=c(0,6),xaxt='n', ann = FALSE)
axis(1, at=0:6, lab=c("Domingo","Lunes","Martes","Miercoles","Jueves","Viernes","Sabado"))
lines(x = anio_1$weekday, y = anio_1$n, type="o", pch=22, lty=2, col="red")
title(main="Demanda por anio y dia", col.main="blue", font.main=4)
legend("topright", pch = 21:22, col = c("blue", "red"), legend = c("Anio 0", "Anio 1"))
demanda_humedad <- bike_df %>% group_by(hum) %>% summarise(n=sum(cnt))
range <- range(0,demanda_humedad$n)
plot( x = demanda_humedad$hum , y = demanda_humedad$n , xlab = "Humedad" , ylab = "Demanda" , ylim=range
, main = "Demanda por humedad" )
demanda_humedad <- bike_df %>% group_by(temp) %>% summarise(n=sum(cnt))
range <- range(0,demanda_humedad$n)
plot( x = demanda_humedad$temp , y = demanda_humedad$n , xlab = "Temperatura" , ylab = "Demanda" , ylim=range
, main = "Demanda por temperatura" )
FIN