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(TotalVentas = sum(Venta))
aux1 %>%
ggplot( aes(x=FechaOrden, y=TotalVentas, color=Segmento))+
geom_line()+hrbrthemes::theme_ft_rc()+
geom_label_repel(aes(x=FechaOrden, y=TotalVentas, color = Segmento, label= rownames(aux1)
))+facet_grid(Categoria~Prioridad)+
geom_smooth(formula = y~poly(x), method = "lm", se= FALSE, size=1)+
labs(title="Histórico 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", size=8),
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.background=element_rect(fill = "transparent",
color = 153,
size = 0.5),
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))

aux1
## # A tibble: 1,668 x 5
## # Groups: FechaOrden, Segmento, Categoria [432]
## FechaOrden Segmento Categoria Prioridad TotalVentas
## <date> <chr> <chr> <chr> <dbl>
## 1 2011-01-01 Consumer Furniture Critical 304.
## 2 2011-01-01 Consumer Furniture High 3965.
## 3 2011-01-01 Consumer Furniture Low 3074.
## 4 2011-01-01 Consumer Furniture Medium 15997.
## 5 2011-01-01 Consumer Office Supplies Critical 1074.
## 6 2011-01-01 Consumer Office Supplies High 3321.
## 7 2011-01-01 Consumer Office Supplies Low 548.
## 8 2011-01-01 Consumer Office Supplies Medium 13758.
## 9 2011-01-01 Consumer Technology Critical 315.
## 10 2011-01-01 Consumer Technology High 1743.
## # ... with 1,658 more rows