Humans

Welcome to #30DayChartChallenge 2023 day 8

Networks
Published

April 8, 2023

library(tidyverse)
tuesdata <- tidytuesdayR::tt_load(2023, week = 06)
big_tech_stock_prices <- tuesdata$big_tech_stock_prices
big_tech_companies <- tuesdata$big_tech_companies
df <- big_tech_stock_prices%>%
  inner_join(big_tech_companies,by="stock_symbol")
df%>%head

HUMAN THEME

library(ggplot2)

# Create example data
big_tech_stock_prices <- data.frame(
  date = seq(as.Date("2021-01-01"), as.Date("2021-12-31"), by = "day"),
  apple = rnorm(365, mean = 140, sd = 10),
  amazon = rnorm(365, mean = 3200, sd = 100),
  facebook = rnorm(365, mean = 350, sd = 20),
  google = rnorm(365, mean = 2500, sd = 50)
)

# Create ggplot with human theme
ggplot(big_tech_stock_prices, aes(x = date)) +
  geom_line(aes(y = apple, color = "Apple")) +
  geom_line(aes(y = amazon, color = "Amazon")) +
  geom_line(aes(y = facebook, color = "Facebook")) +
  geom_line(aes(y = google, color = "Google")) +
  scale_color_manual(values = c("Apple" = "#A9A9A9", "Amazon" = "#FFA500", "Facebook" = "#4169E1", "Google" = "#008000")) +
  labs(title = "Big Tech Stock Prices", x = "Date", y = "Stock Price") +
  theme_minimal() +
  theme(
    plot.title = element_text(size = 20, face = "bold", margin = margin(b = 20)),
    axis.title = element_text(size = 16, face = "bold"),
    axis.text = element_text(size = 14),
    legend.title = element_blank(),
    legend.text = element_text(size = 14),
    legend.position = "bottom"
  )
my_companies<- c("Apple Inc.","Microsoft Corporation","Netflix, Inc.", "Tesla, Inc.")

library(scales)
df %>% 
  filter(company%in%my_companies)%>%
  select(date,volume,company)%>%
  group_by(company)%>%
  mutate(mean=mean(volume,na.rm = TRUE),
         sd=sd(volume,na.rm = TRUE))%>%
  ggplot(aes(x = date)) +
  geom_hline(aes(yintercept=mean,color=company),linewidth=0.3)+
  geom_line(aes(y = volume, group=company, color=company),
            linewidth=0.1,key_glyph="timeseries") +
  scale_y_log10(expand=c(0,0),
                labels = label_number(scale_cut = cut_short_scale()))+
  scale_x_date(expand = c(0,0))+
  scale_color_manual(values = c("Apple Inc." = "#0071bc",
                                "Microsoft Corporation" = "#FFA500", 
                                "Netflix, Inc." = "#fff1e0", 
                                "Tesla, Inc." = "#c15a4f")) +
  guides(color=guide_legend(nrow = 2))+
  labs(title = "Big Tech Stock Prices", y = "Stock Price Volume",
       subtitle="Humans activity - Best Companies Mean Trend",
       caption="\nDataSource: #TidyTuesday 2023 week6 Big Tech Stock Prices\nDataViz: Federica Gazzelloni #30DayChartChallenge 2023 Day8 - humans\n") +
  ggthemes::theme_economist()+
  theme(text = element_text(family="Roboto Condensed",color="#250c5f"),
    plot.title = element_text(size = 25, face = "bold", margin = margin(b = 20)),
    plot.background = element_rect(color="#89a5b9",fill="#89a5b9"),
    panel.background = element_rect(color="#89a5b9",fill="#89a5b9"),
    axis.title = element_text(size = 16, face = "bold"),
    axis.text = element_text(size = 12),
    axis.title.x = element_blank(),
    legend.key.size = unit(15,units = "pt"),
    #legend.key.width = unit(15,units = "pt"),
    legend.title = element_blank(),
    legend.box.background = element_rect(color="#250c5f",fill="#250c5f"),
    legend.text = element_text(size = 11,color="white"),
    legend.position = "bottom",
    panel.grid = element_line(linewidth=0.0),
    axis.line.y = element_line(),
    axis.text.y = element_text(hjust=1)
  )
ggsave("w6_BTSP.png",
       width = 7,height = 5)