setwd("~/UNIVERSIDAD/QUINTO SEMESTRE/INFORMÁTICA/parcial")

library(tidyverse)
library(data.table)
library(lubridate)
library(ggrepel)
library(scales)
library(hrbrthemes)
library(ggplot2)

data <- fread("superstore.csv")

aux1 <- data %>% 
  mutate(FecOrden =  as.Date(FecOrden, "%d/%m/%Y"),
         FecEnvio =  as.Date(FecEnvio, "%d/%m/%Y"),
         FechaOrden= floor_date(FecOrden, unit = "month")
  ) %>% 
  group_by(FechaOrden, Segmento, Categoria, Prioridad) %>% 
  summarise(TotVentas = sum(Venta))

ggplot(aux1, aes(x=FechaOrden, y=TotVentas, colour = Segmento )) + 
  geom_line()  + 
  hrbrthemes::theme_ft_rc()+
  labs(title="Histórico de Ventas",
       subtitle="Segregación Por Categoria y Prioridad",
       colour = "Segmento de Cliente")+
  facet_grid(Categoria~Prioridad,scales='free_y', space='free_y')+
  geom_label_repel(aes ( label = TotVentas, colour = Segmento))+
  scale_color_hue(labels = c("Consumidor", "Corporativo","Home Ofice"))+
  theme(legend.position = "bottom")+
  geom_smooth(size = 0.5, se=FALSE)+
  theme(legend.text = element_text(color = "steelblue", size = 8))+
  theme(axis.title=element_text(size=10,face="bold"))+
  theme(axis.text.y = element_text(colour = "steelblue",size=8,face = "bold"))+
  theme(axis.text.x = element_text(colour = "steelblue",size=8,face = "bold"))