Codigo Introductorio

  1. Directorio
setwd("C:/Programacion en R/1. INF. PARA ECONOMISTAS/PARCIAL2")
  1. Librearias Necesarias
library(tidyverse)
library(readxl)
library(data.table)
library(lubridate)
library(ggrepel)
library(scales)
library(hrbrthemes)
library(ggplot2)
  1. Datos a utilizar
data <- fread("superstore.csv")
View(data)

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))
View(aux1)

Aproximaciones para replicar la gráfica

Aproximación 1

aux1 %>%
  ggplot(aes(x = FechaOrden,y = TotVentas, color =Segmento)) +
  geom_line() +
  geom_smooth(method = lm, se = FALSE)+ 
  hrbrthemes::theme_ft_rc()+
  guides(color = guide_legend(title = "Segmento de Cliente"))+
  labs(x="Fecha de la Orden",                                                          
       y="Total de Ventas",                                                   
       title = "Histórico de Ventas",
       subtitle = "Segregación por Categoria y Prioridad")+
  theme(legend.text=element_text(color="steelblue",size=8), 
        axis.text.y = element_text(size=5, face = c("bold"), colour = "steelblue"),
        axis.text.x = element_text(angle= 90, size=5, face = c("bold"), colour = "steelblue"),
        legend.position="bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "gray10"),
        plot.margin = margin(t = 5,  
                             r = 5,  
                             b = 5,  
                             l = 5))

Se aplica el tema correspondiente con la intención de mirar solamente la Fecha de la Orden y el Total de Ventas

1000

Aproximación 2

aux1 %>%
  ggplot(aes(x = FechaOrden,y = TotVentas, color =Segmento)) +
  geom_line() +
  geom_smooth(method = lm, se = FALSE)+ 
  facet_grid(Categoria~.)+
  guides(color = guide_legend(title = "Segmento de Cliente"))+
  labs(x="Fecha de la Orden",                                                          
       y="Total de Ventas",                                                   
       title = "Histórico de Ventas",
       subtitle = "Segregación por Categoria y Prioridad")+
  theme(legend.text=element_text(color="steelblue",size=8), 
        axis.text.y = element_text(size=8, face = c("bold"), colour = "steelblue"),
        axis.text.x = element_text(angle= 90, size=8, face = c("bold"), colour = "steelblue"),
        legend.position="bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "gray10"),
        plot.margin = margin(t = 5,  
                             r = 5,  
                             b = 5,  
                             l = 5))

Se divide el análisis por medio de la Categoria: Furniture, Office y Technology

1000

Aproximación 3

aux1 %>%
  ggplot(aes(x = FechaOrden,y = TotVentas, color =Segmento)) +
  geom_line() +
  geom_smooth(method = lm, se = FALSE)+ 
  facet_grid(.~Prioridad)+
  guides(color = guide_legend(title = "Segmento de Cliente"))+
  labs(x="Fecha de la Orden",                                                          
       y="Total de Ventas",                                                   
       title = "Histórico de Ventas",
       subtitle = "Segregación por Categoria y Prioridad")+
  theme(legend.text=element_text(color="steelblue",size=8), 
        axis.text.y = element_text(size=8, face = c("bold"), colour = "steelblue"),
        axis.text.x = element_text(angle= 90, size=8, face = c("bold"), colour = "steelblue"),
        legend.position="bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "gray10"),
        plot.margin = margin(t = 5,  
                             r = 5,  
                             b = 5, 
                             l = 5))

Se divide el análisis por medio de la Prioridad: Critical, High, Low y Medium

1000

Aproximación Final

aux1 %>%
  ggplot(aes(x = FechaOrden,y = TotVentas, color =Segmento)) +
  geom_line() +
  geom_smooth(method = lm, se = FALSE)+ 
  facet_grid(Categoria~Prioridad)+
  hrbrthemes::theme_ft_rc()+
  guides(color = guide_legend(title = "Segmento de Cliente"))+
  labs(x="Fecha de la Orden",                                                          
       y="Total de Ventas",                                                   
       title = "Histórico de Ventas",
       subtitle = "Segregación por Categoria y Prioridad")+
  theme(legend.text=element_text(color="steelblue",size=8), 
        axis.text.y = element_text(size=8, face = c("bold"), colour = "steelblue"),
        axis.text.x = element_text(angle= 90, size=8, face = c("bold"), colour = "steelblue"),
        legend.position="bottom",
        panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(),
        panel.background = element_rect(colour = "gray10"),
        plot.margin = margin(t = 5,  
                             r = 5,  IBAUEYABIIyAi
                             b = 5,  
                             l = 5))

Se divide el análisis por medio de la Categoria y Prioridad.

La gráfica está replicada bastante bien a excepción de las siguientes fallas:

Fallas en la aproximación

1200