#PARCIAL 2
setwd("C:/INFORMATICA ECONOMISTAS/PARCIAL 2")
library(tidyverse)
library(data.table)
library(lubridate)
library(ggrepel)
library(scales)
library(hrbrthemes)

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))

aux1 %>% 
  ggplot(aes(x=FechaOrden,y=TotVentas, color=Segmento))+
  geom_line()+
  geom_label_repel(aes(x=FechaOrden, y=TotVentas, color = Segmento,
                       label = rownames(aux1)))+
  
  facet_grid(Categoria~Prioridad)+
  geom_smooth(method = "lm", formula = y~poly(x), se = FALSE)+
  hrbrthemes::theme_ft_rc()+
  labs(title="Historico de Ventas",subtitle = "Segregación por Categoria y Prioridad",
       x="Fecha de orden", y="Total de ventas", color="Segmento de cliente")+
  theme(legend.text=element_text(color="steelblue"),
        axis.text.y = element_text(size=8, face = c("bold"),
                                   colour = "steelblue"),
        axis.text.x = element_text(size=8, face = c("bold"),
                                   colour = "steelblue",angle=90),
        legend.position = "bottom",
        axis.ticks=element_blank(),
        panel.border = element_rect(fill = "transparent",
                                    color = 153,
                                    size = 0,5),
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank()) +
  scale_y_continuous(breaks = seq(0,60000,10000),
                     label = function(x) paste0('$', x))