Punto 1
setwd("~/informatica/parcial 2 info")
library(tidyverse)
library(data.table)
library(lubridate)
library(ggrepel)
library(scales)
library(hrbrthemes)
data <- fread("superstore.csv")
glimpse(data)
## Rows: 51,290
## Columns: 20
## $ FecOrden <chr> "01/01/2011", "01/01/2011", "01/01/2011", "01/01~
## $ FecEnvio <chr> "06/01/2011", "08/01/2011", "05/01/2011", "05/01~
## $ TipoEnvio <chr> "Standard Class", "Standard Class", "Second Clas~
## $ IdentificacionCliente <chr> "TB-11280", "JH-15985", "AT-735", "EM-14140", "J~
## $ Segmento <chr> "Consumer", "Consumer", "Consumer", "Home Office~
## $ Ciudad <chr> "Constantine", "Wagga Wagga", "Budapest", "Stock~
## $ Estado <chr> "Constantine", "New South Wales", "Budapest", "S~
## $ Pais <chr> "Algeria", "Australia", "Hungary", "Sweden", "Au~
## $ Mercado <chr> "Africa", "APAC", "EMEA", "EU", "APAC", "APAC", ~
## $ Region <chr> "Africa", "Oceania", "EMEA", "North", "Oceania",~
## $ IdProducto <chr> "OFF-TEN-10000025", "OFF-SU-10000618", "OFF-TEN-~
## $ Categoria <chr> "Office Supplies", "Office Supplies", "Office Su~
## $ SubCategoria <chr> "Storage", "Supplies", "Storage", "Paper", "Furn~
## $ Producto <chr> "Tenex Lockers, Blue", "Acme Trimmer, High Speed~
## $ Venta <dbl> 408.300, 120.366, 66.120, 44.865, 113.670, 55.24~
## $ Cantidad <int> 2, 3, 4, 3, 5, 2, 2, 2, 1, 3, 5, 2, 6, 5, 3, 2, ~
## $ Descuento <dbl> 0.00, 0.10, 0.00, 0.50, 0.10, 0.10, 0.00, 0.15, ~
## $ Profit <dbl> 106.1400, 36.0360, 29.6400, -26.0550, 37.7700, 1~
## $ GastoEnvio <dbl> 35.46, 9.72, 8.17, 4.82, 4.70, 1.80, 57.30, 54.6~
## $ Prioridad <chr> "Medium", "Medium", "High", "High", "Medium", "M~
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(data)
#View(aux1)
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(formula = y ~ poly(x), method = "lm", se = FALSE) +
hrbrthemes::theme_ft_rc() +
labs(title = "Histórico de Ventas",
subtitle = "Segregación por Categoria y Prioridad",
x = "Fecha de la 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(angle = 90, size = 8,
face = c("bold"), colour = "steelblue"),
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))
