Pregunta 1; P1

rm(list=ls())
library(data.table)
library(ggplot2)
library(janitor)
library(plotly)
library(RColorBrewer)
library(tidyverse)
library(lubridate)
Store <- fread("Superstore.csv", encoding = 'UTF-8')

Medida previa

Store<-Store%>%
  mutate(`Order Date` = mdy(`Order Date`),
         `Ship Date` = mdy(`Ship Date`),
         Ship = `Ship Date` - `Order Date`)
Store$`Order Date` <- as.Date(Store$`Order Date`)

Pregunta 2; P2

ggplot(Store,aes(x=`Ship Mode`, y=`Ship`)) +  geom_boxplot(color="blue")

Pregunta 3; P.3 + Pregunta 4; P.4

Confirmación de Grafico

Store[,sum(Sales), by=.(Store$State)]
ggplot(Store,aes(x=State, y=Sales, fill=Sales)) + geom_col(position = "stack")  + labs(x="States", y="Sales", title = "Sales ", subtitle = "By State", caption = "source: Kaggle" ) + theme(axis.text.x = element_text(angle=90, vjust=0.5))

Confirmación de Grafico

Store[,sum(Profit), by=.(Store$State)]
ggplot(Store,aes(x=State, y= Profit, fill= Profit)) + geom_col(position = "stack")  + labs(x="States", y="Profits", title = "Profits ", subtitle = "By State", caption = "source: Kaggle" ) + theme(axis.text.x = element_text(angle=90, vjust=0.5))

Pregunta 5; P.5

California State

California<-Store[State=="California"]

Category and Sub.Category

ggplot(California,aes(x=`Sub-Category`, y=`Sales`, fill=`Category`)) + geom_col()+facet_wrap(~`Category`)+ labs(x="Sub-Category", y="Sales", title = "Sales California", subtitle = "By Category and Sub-Category", caption = "Fuente: Kaggle" ) + theme(axis.text.x = element_text(angle=90, vjust=0.5))

California[,sum(Sales), by=.(Category)]
California[,sum(Sales), by=.(`Sub-Category`)]

Sub-Categoria más vendida, de acuerdo a su Categoria.

ggplot(California,aes(x=`Sub-Category`, y=`Sales`, fill=Category)) + geom_col() + labs(x="Sub-Category", y="Sales", title = "Sales California", subtitle = "By Category and Sub-Category", caption = "Fuente: Kaggle" ) + theme(axis.text.x = element_text(angle=90, vjust=0.5))

Categoria más vendida, de acuerdo a su Sub-Categoria.

ggplot(California,aes(x=Category, y=`Sales`, fill=`Sub-Category`)) + geom_col(`Sub-Category` = "fill") + labs(x="Category", y="Sub-Category", title = "California", subtitle = "By Category and Sub-Category", caption = "Fuente: Kaggle" ) + theme(axis.text.x = element_text(angle=90, vjust=0.5))

Pregunta 6; P.6

California[,year:=format(as.Date(`Order Date`),"%Y")]
California1<- California[Category=="Furniture"]
ggplot(data=California1,aes(x=`Order Date`,y=Sales))+geom_line(color="blue")+geom_point(color="blue") + labs(x="Year", y="Sales", title = "California", subtitle = "By Category of furniture", caption = "Fuente: Kaggle" ) + theme(axis.text.x = element_text(angle=0, vjust=0.5))

Pregunta 7

Store_California<-Store[,.(Total=sum(Sales)),by=.(State)][,.(State,`Proporción`=Total/sum(Total)*100)]
Store[,sum(Sales)]

Grafico que incluye los porcentajes de ventas por Estado

States<-c(Store$State)
Store_1 <- ggplot(Store_California[State %in% States], aes(x=State, y=`Proporción`, text=paste("Nombre:",State, "\n","Proportion:",`Proporción` ))) +  geom_point(color="blue")+ theme(axis.text.x = element_text(angle=90, vjust=10))
ggplotly(Store_1, tooltip = "text")