-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake-ticker-plot.R
41 lines (35 loc) · 1.09 KB
/
make-ticker-plot.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
library(tidyverse)
library(knitr)
# read data
x <- read_csv("wsb.csv", col_types = cols(
ticker = col_character(),
date = col_double(),
title = col_character(),
url = col_character()
))
# 10 most mentioned stock tickers
data <- x %>%
select(ticker) %>%
group_by(ticker) %>%
summarize(count = n()) %>%
arrange(desc(count)) %>%
slice(1:10) %>%
mutate(ticker = as.factor(ticker))
#get current date as a string
date <- toString(Sys.Date())
#get most mentioned stock as a string
most_mentioned <- data %>%
slice(1)
ticker <- toString(most_mentioned$ticker)
# create plot
ticker_plot <- data %>%
ggplot(mapping = aes(fct_reorder(ticker, count), count)) +
geom_col(fill = "lightblue") +
geom_text(aes(label = count), position = position_dodge(width = 0.9), vjust = -0.25) +
theme_classic() +
labs(title = "Frequently Mentioned Tickers on WallStreetBets",
subtitle = paste(ticker, "was the most commonly mentioned stock ticker on", date),
x = "Ticker",
y = "Post Title Mentions",
caption = "Source: r/WallStreetBets")
write_rds(ticker_plot, "ticker-plot.rds")