Define server logic required to draw a chart
shinyServer <- function(input, output) {
output$distPlot1 <- renderPlot({
# Use just the last 100 values for illustration
if(input$chart == "TSLA") {
symb <- "TSLA"
tsla <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
chartSeries(tsla,
theme = chartTheme("white",
bg.col = 'grey96',
fg.col = "grey70",
grid.col = "white",
border = "transparent"),
up.col = 'darkblue', dn.col = 'tomato',
log.scale = TRUE,
name = "The Tesla stock bubble of 2021 ($TSLA)")
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
abline(32, 0, col = annotation_col)
text(100, 40, annotation_lab, col = annotation_col, cex = 0.8)
} else if(input$chart == "GOOGL") {
symb <- "GOOGL"
googl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
chartSeries(googl,
theme = chartTheme("white",
bg.col = 'grey96',
fg.col = "grey70",
grid.col = "white",
border = "transparent"),
up.col = 'darkblue', dn.col = 'tomato',
log.scale = TRUE,
name = "The Google stock bubble of 2021 ($GOOGL)")
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
abline(32, 0, col = annotation_col)
text(100, 40, annotation_lab, col = annotation_col, cex = 0.8)
} else if(input$chart == "FB") {
symb <- "FB"
fb <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
chartSeries(fb,
theme = chartTheme("white",
bg.col = 'grey96',
fg.col = "grey70",
grid.col = "white",
border = "transparent"),
up.col = 'darkblue', dn.col = 'tomato',
log.scale = TRUE,
name = "The Facebook stock bubble of 2021 ($FB)")
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
abline(32, 0, col = annotation_col)
text(100, 40, annotation_lab, col = annotation_col, cex = 0.8)
} else if(input$chart == "AMZN") {
symb <- "AMZN"
amzn <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
chartSeries(amzn,
theme = chartTheme("white",
bg.col = 'grey96',
fg.col = "grey70",
grid.col = "white",
border = "transparent"),
up.col = 'darkblue', dn.col = 'tomato',
log.scale = TRUE,
name = "The Amazon stock bubble of 2021 ($AMZN)")
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
abline(32, 0, col = annotation_col)
text(100, 40, annotation_lab, col = annotation_col, cex = 0.8)
} else if(input$chart == "AAPL") {
symb <- "AAPL"
aapl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
chartSeries(aapl,
theme = chartTheme("white",
bg.col = 'grey96',
fg.col = "grey70",
grid.col = "white",
border = "transparent"),
up.col = 'darkblue', dn.col = 'tomato',
log.scale = TRUE,
name = "The Apple stock bubble of 2021 ($AAPL)")
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
abline(32, 0, col = annotation_col)
text(100, 40, annotation_lab, col = annotation_col, cex = 0.8)
} else {
symb <- "MSFT"
msft <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
chartSeries(msft,
theme = chartTheme("white",
bg.col = 'grey96',
fg.col = "grey70",
grid.col = "white",
border = "transparent"),
up.col = 'darkblue', dn.col = 'tomato',
log.scale = TRUE,
name = "The Microsoft stock bubble of 2021 ($MSFT)")
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
abline(32, 0, col = annotation_col)
text(100, 40, annotation_lab, col = annotation_col, cex = 0.8)
}
})
output$distplot2 <- renderPlot({
# Use just the last 100 values for illustration
if(input$chart == "TSLA") {
symb <- "TSLA"
tsla <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 50)
names(tsla) <- gsub(glue("{symb}\\."), "", names(tsla))
tsla %>%
as_tibble() %>%
mutate(date = time(tsla)) %>%
group_by(month(date), year(date)) %>%
mutate(direction = ifelse(Close > Open, "Bullish", "Bearish"),
lab = ifelse(day(date) == min(day(date)) | Volume > 100e6 | Close > 300,
format(date, "%e %b %y"), "")) %>%
ungroup() %>%
ggplot(aes(x = Volume / 1e6, y = Close, label = lab)) +
geom_path(colour = "grey") +
geom_point(aes(colour = direction), alpha = 0.5) +
geom_text(aes(colour = direction), hjust = 0, size = 3, nudge_x = 0.015) +
scale_x_log10(label = comma_format(suffix = "m", accuracy = 1),
limits = c(1, 300)) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_colour_manual(values = c(Bullish = "darkblue", Bearish = "tomato")) +
labs(x = "Volume (log scale)",
y = "Closing price (log scale)",
title = "The Tesla stock bubble of 2021 ($TSLA)",
colour = "Direction of sentiment over the day:",
subtitle = "Connected scatter plot of latest 50 closing price.")
} else if(input$chart == "GOOGL") {
symb <- "GOOGL"
googl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 50)
names(googl) <- gsub(glue("{symb}\\."), "", names(googl))
googl %>%
as_tibble() %>%
mutate(date = time(googl)) %>%
group_by(month(date), year(date)) %>%
mutate(direction = ifelse(Close > Open, "Bullish", "Bearish"),
lab = ifelse(day(date) == min(day(date)) | Volume > 100e6 | Close > 1000,
format(date, "%e %b %y"), "")) %>%
ungroup() %>%
ggplot(aes(x = Volume / 1e6, y = Close, label = lab)) +
geom_path(colour = "grey") +
geom_point(aes(colour = direction), alpha = 0.5) +
geom_text(aes(colour = direction), hjust = 0, size = 3, nudge_x = 0.015) +
scale_x_log10(label = comma_format(suffix = "m", accuracy = 1),
limits = c(1, 300)) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_colour_manual(values = c(Bullish = "darkblue", Bearish = "tomato")) +
labs(x = "Volume (log scale)",
y = "Closing price (log scale)",
title = "The Google stock bubble of 2021 ($GOOGL)",
colour = "Direction of sentiment over the day:",
subtitle = "Connected scatter plot of latest 50 closing price.")
} else if(input$chart == "FB") {
symb <- "FB"
fb <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 50)
names(fb) <- gsub(glue("{symb}\\."), "", names(fb))
fb %>%
as_tibble() %>%
mutate(date = time(fb)) %>%
group_by(month(date), year(date)) %>%
mutate(direction = ifelse(Close > Open, "Bullish", "Bearish"),
lab = ifelse(day(date) == min(day(date)) | Volume > 100e6 | Close > 200,
format(date, "%e %b %y"), "")) %>%
ungroup() %>%
ggplot(aes(x = Volume / 1e6, y = Close, label = lab)) +
geom_path(colour = "grey") +
geom_point(aes(colour = direction), alpha = 0.5) +
geom_text(aes(colour = direction), hjust = 0, size = 3, nudge_x = 0.015) +
scale_x_log10(label = comma_format(suffix = "m", accuracy = 1),
limits = c(1, 300)) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_colour_manual(values = c(Bullish = "darkblue", Bearish = "tomato")) +
labs(x = "Volume (log scale)",
y = "Closing price (log scale)",
title = "The Facebook stock bubble of 2021 ($FB)",
colour = "Direction of sentiment over the day:",
subtitle = "Connected scatter plot of latest 50 closing price.")
} else if(input$chart == "AMZN" ) {
symb <- "AMZN"
amzn <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 50)
names(amzn) <- gsub(glue("{symb}\\."), "", names(amzn))
amzn %>%
as_tibble() %>%
mutate(date = time(amzn)) %>%
group_by(month(date), year(date)) %>%
mutate(direction = ifelse(Close > Open, "Bullish", "Bearish"),
lab = ifelse(day(date) == min(day(date)) | Volume > 100e6 | Close > 2000,
format(date, "%e %b %y"), "")) %>%
ungroup() %>%
ggplot(aes(x = Volume / 1e6, y = Close, label = lab)) +
geom_path(colour = "grey") +
geom_point(aes(colour = direction), alpha = 0.5) +
geom_text(aes(colour = direction), hjust = 0, size = 3, nudge_x = 0.015) +
scale_x_log10(label = comma_format(suffix = "m", accuracy = 1),
limits = c(1, 300)) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_colour_manual(values = c(Bullish = "darkblue", Bearish = "tomato")) +
labs(x = "Volume (log scale)",
y = "Closing price (log scale)",
title = "The Amazon stock bubble of 2021 ($AMZN)",
colour = "Direction of sentiment over the day:",
subtitle = "Connected scatter plot of latest 50 closing price.")
} else if(input$chart == "AAPL" ) {
symb <- "AAPL"
aapl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 50)
names(aapl) <- gsub(glue("{symb}\\."), "", names(aapl))
aapl %>%
as_tibble() %>%
mutate(date = time(aapl)) %>%
group_by(month(date), year(date)) %>%
mutate(direction = ifelse(Close > Open, "Bullish", "Bearish"),
lab = ifelse(day(date) == min(day(date)) | Volume > 100e6 | Close > 100,
format(date, "%e %b %y"), "")) %>%
ungroup() %>%
ggplot(aes(x = Volume / 1e6, y = Close, label = lab)) +
geom_path(colour = "grey") +
geom_point(aes(colour = direction), alpha = 0.5) +
geom_text(aes(colour = direction), hjust = 0, size = 3, nudge_x = 0.015) +
scale_x_log10(label = comma_format(suffix = "m", accuracy = 1),
limits = c(1, 300)) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_colour_manual(values = c(Bullish = "darkblue", Bearish = "tomato")) +
labs(x = "Volume (log scale)",
y = "Closing price (log scale)",
title = "The Apple stock bubble of 2021 ($AAPL)",
colour = "Direction of sentiment over the day:",
subtitle = "Connected scatter plot of latest 50 closing price.")
} else if(input$chart == "MSFT" ) {
symb <- "MSFT"
msft <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 50)
names(msft) <- gsub(glue("{symb}\\."), "", names(msft))
msft %>%
as_tibble() %>%
mutate(date = time(msft)) %>%
group_by(month(date), year(date)) %>%
mutate(direction = ifelse(Close > Open, "Bullish", "Bearish"),
lab = ifelse(day(date) == min(day(date)) | Volume > 100e6 | Close > 200,
format(date, "%e %b %y"), "")) %>%
ungroup() %>%
ggplot(aes(x = Volume / 1e6, y = Close, label = lab)) +
geom_path(colour = "grey") +
geom_point(aes(colour = direction), alpha = 0.5) +
geom_text(aes(colour = direction), hjust = 0, size = 3, nudge_x = 0.015) +
scale_x_log10(label = comma_format(suffix = "m", accuracy = 1),
limits = c(1, 300)) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_colour_manual(values = c(Bullish = "darkblue", Bearish = "tomato")) +
labs(x = "Volume (log scale)",
y = "Closing price (log scale)",
title = "The Microsoft stock bubble of 2021 ($MSFT)",
colour = "Direction of sentiment over the day:",
subtitle = "Connected scatter plot.")
}
})
output$pricePlot <- renderPlot({
if(input$chart == "TSLA" & input$PriceInput == "over $100") {
symb <- "TSLA"
tsla <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(tsla) <- gsub(glue("{symb}\\."), "", names(tsla))
p <- tsla[which(tsla$Close >= 100)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Tesla stock bubble of 2021 ($TSLA)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "TSLA" & input$PriceInput == "over $300") {
symb <- "TSLA"
tsla <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(tsla) <- gsub(glue("{symb}\\."), "", names(tsla))
p <- tsla[which(tsla$Close >= 300)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Tesla stock bubble of 2021 ($TSLA)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "TSLA" & input$PriceInput == "over $500") {
symb <- "TSLA"
tsla <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(tsla) <- gsub(glue("{symb}\\."), "", names(tsla))
p <- tsla[which(tsla$Close >= 500)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Tesla stock bubble of 2021 ($TSLA)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "GOOGL" & input$PriceInput == "over $100") {
symb <- "GOOGL"
googl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(googl) <- gsub(glue("{symb}\\."), "", names(googl))
p <- googl[which(googl$Close >= 100)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Google stock bubble of 2021 ($GOOGL)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "GOOGL" & input$PriceInput == "over $300") {
symb <- "GOOGL"
googl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(googl) <- gsub(glue("{symb}\\."), "", names(googl))
p <- googl[which(googl$Close >= 300)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Google stock bubble of 2021 ($GOOGL)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "GOOGL" & input$PriceInput == "over $500") {
symb <- "GOOGL"
googl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(googl) <- gsub(glue("{symb}\\."), "", names(googl))
p <- googl[which(googl$Close >= 500)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Google stock bubble of 2021 ($GOOGL)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "FB" & input$PriceInput == "over $100") {
symb <- "FB"
fb <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(fb) <- gsub(glue("{symb}\\."), "", names(fb))
p <- fb[which(fb$Close >= 100)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Facebook stock bubble of 2021 ($FB)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "FB" & input$PriceInput == "over $300") {
symb <- "FB"
fb <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(fb) <- gsub(glue("{symb}\\."), "", names(fb))
p <- fb[which(fb$Close >= 300)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Facebook stock bubble of 2021 ($FB)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "FB" & input$PriceInput == "over $500") {
symb <- "FB"
fb <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(fb) <- gsub(glue("{symb}\\."), "", names(fb))
p <- fb[which(fb$Close >= 500)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Facebook stock bubble of 2021 ($FB)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "AMZN" & input$PriceInput == "over $100") {
symb <- "AMZN"
amzn <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(amzn) <- gsub(glue("{symb}\\."), "", names(amzn))
p <- amzn[which(amzn$Close >= 100)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Amazon stock bubble of 2021 ($AMZN)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "AMZN" & input$PriceInput == "over $300") {
symb <- "AMZN"
amzn <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(amzn) <- gsub(glue("{symb}\\."), "", names(amzn))
p <- amzn[which(amzn$Close >= 300)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Amazon stock bubble of 2021 ($AMZN)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "AMZN" & input$PriceInput == "over $500") {
symb <- "AMZN"
amzn <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(amzn) <- gsub(glue("{symb}\\."), "", names(amzn))
p <- amzn[which(amzn$Close >= 500)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Amazon stock bubble of 2021 ($AMZN)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "AAPL" & input$PriceInput == "over $100") {
symb <- "AAPL"
aapl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(aapl) <- gsub(glue("{symb}\\."), "", names(aapl))
p <- aapl[which(aapl$Close >= 100)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Apple stock bubble of 2021 ($AAPL)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "AAPL" & input$PriceInput == "over $300") {
symb <- "AAPL"
aapl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(aapl) <- gsub(glue("{symb}\\."), "", names(aapl))
p <- aapl[which(aapl$Close >= 300)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Apple stock bubble of 2021 ($AAPL)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "AAPL" & input$PriceInput == "over $500") {
symb <- "AAPL"
aapl <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(aapl) <- gsub(glue("{symb}\\."), "", names(aapl))
p <- aapl[which(aapl$Close >= 500)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Apple stock bubble of 2021 ($AAPL)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "MSFT" & input$PriceInput == "over $100") {
symb <- "MSFT"
msft <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(msft) <- gsub(glue("{symb}\\."), "", names(msft))
p <- msft[which(msft$Close >= 100)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Microsoft stock bubble of 2021 ($MSFT)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "MSFT" & input$PriceInput == "over $300") {
symb <- "MSFT"
msft <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(msft) <- gsub(glue("{symb}\\."), "", names(msft))
p <- msft[which(msft$Close >= 300)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Microsoft stock bubble of 2021 ($MSFT)",
subtitle = "Line plot for price with volume shown as point size.")
} else if(input$chart == "MSFT" & input$PriceInput == "over $500") {
symb <- "MSFT"
msft <- tail(getSymbols(symb, src = 'yahoo', auto.assign = FALSE), 100)
names(msft) <- gsub(glue("{symb}\\."), "", names(msft))
p <- msft[which(msft$Close >= 500)]
annotation_lab <- "Highest plausible actual value based on firm's revenue, etc.: $100"
annotation_col <- "steelblue"
p %>%
as_tibble() %>%
mutate(date = time(p)) %>%
ggplot(aes(x = date, y = Close)) +
geom_hline(yintercept = 20, colour = "steelblue") +
geom_line() +
geom_point(aes(size = Volume / 1e6), alpha = 0.5) +
annotate("text", x = Sys.Date() - 50, y = 32, size = 3, hjust = 1,
colour = annotation_col,
label = annotation_lab) +
scale_y_log10(label = dollar_format(accuracy = 1)) +
scale_x_date(date_labels = "%b %Y") +
scale_size_area(label = comma) +
labs(x = "",
y = "Closing price (log scale)",
size = "Volume (M)",
title = "The Microsoft stock bubble of 2021 ($MSFT)",
subtitle = "Line plot for price with volume shown as point size.")
}
})
}