Classwork 16

Visualizing Time Trends

Author

Byeong-Hak Choe

Published

November 11, 2026

NoteNote

Complete the questions and submit your responses on the corresponding Brightspace page.

Complete the code in an R script and keep your brief written interpretations with it. This page contains its own setup and data definitions; no earlier classwork is required.

Setup and data

The course file contains daily stock-trading records from October 1–30, 2026. Use Microsoft and Meta to study daily trading volume, the number of shares traded during a day. The supplied code keeps these two companies. read_csv() recognizes the Date column as calendar dates automatically.

library(tidyverse)
library(ggthemes)

tech_october <- read_csv("https://bcdanl.github.io/data/tech_stocks_2026_10.csv") |>
  filter(Ticker == "MSFT" | Ticker == "META" )
Variable Meaning
Date Trading day
Ticker Company identifier: MSFT = Microsoft, META = Meta
Volume Number of shares traded during that trading day

Each row represents one company’s trading record on one trading day. There are 22 observed trading days per company. Volume counts shares traded, not distinct traders or dollars. These are historical records, not current trading activity.

Filling-in-the-blank: 1. Trading activity over time

Use this supplied filter to keep Microsoft’s rows. Complete the plot so it marks each observed trading day and connects the observations in date order.

microsoft_october <- tech_october |>
  filter(Ticker == "MSFT")

ggplot(data = microsoft_october,
       mapping = aes(x = ____,
                     y = ____)) +
  ____(color = "grey60") +
  ____(color = "steelblue")

Now add + geom_smooth() to the plot, using the default settings. Explain what the points, connecting line, and smooth curve each show. Why doesn’t the smooth curve tell us what trading volume will be in November?

The blanks are Date, Volume, geom_line, and geom_point.

microsoft_october <- tech_october |>
  filter(Ticker == "MSFT")

ggplot(data = microsoft_october,
       mapping = aes(x = Date,
                     y = Volume)) +
  geom_line(color = "grey60") +
  geom_point(color = "steelblue")

Microsoft daily trading volume in October 2026, with steel blue points for observed trading days and a grey line connecting them in date order. Axis labels show dates and shares traded without scientific notation.

Each point records how many Microsoft shares traded on one observed trading day. On October 1, for example, the point represents 19,731,882 shares. The horizontal axis shows calendar dates and the vertical axis shows shares traded, not dollars or distinct traders. The grey line connects the 22 observations in date order. Its segments do not add observations for weekends or other dates missing from the file.

Add the default smooth curve:

ggplot(data = microsoft_october,
       mapping = aes(x = Date,
                     y = Volume)) +
  geom_line(color = "grey60") +
  geom_point(color = "steelblue") +
  geom_smooth()

Microsoft daily trading-volume points and connecting line with a default smooth curve and uncertainty ribbon summarizing the observed October 2026 dates.

geom_smooth() estimates the average pattern across the observed dates, making broad movement easier to see without following every daily fluctuation. The curve need not pass through the points. Its shaded ribbon shows uncertainty around the fitted average, rather than the full spread of daily volumes. This curve summarizes the October observations; it supplies neither November observations nor a forecast of November trading volume.

Interpretation: 2. Two companies, separate lines

Use the supplied plot to compare Microsoft and Meta on the same axes. The code maps both color and line type to Ticker.

ggplot(data = tech_october,
       mapping = aes(x = Date,
                     y = Volume,
                     color = Ticker,
                     linetype = Ticker)) +
  geom_line(linewidth = 1) +
  scale_color_colorblind()

Microsoft and Meta daily trading volumes on shared axes. Color and line type identify each company. Meta has the higher late-month peak on October 27; Microsoft peaks on October 29.

Why does this code draw one line for each company? Explain what would go wrong if you mapped only Date and Volume and used geom_line() on the combined data. Compare the late-month peaks: which company’s peak is higher, and do the peaks occur on the same day?

Ticker is categorical. Mapping it to color and line type gives ggplot a separate group for each company. Color and line type also give readers two ways to distinguish the lines. Without either mapping or another way to group by Ticker, geom_line() would treat all the rows as one series. It could connect Meta’s volume to Microsoft’s volume on the same date or on successive dates, producing jumps that do not represent either company’s history.

The two lines share the same dates and shares-traded scale. Meta had the higher peak: 51,334,081 shares on October 27. Microsoft peaked two days later, at 39,333,217 shares on October 29. The dates of those peaks differ, and neither company peaked on the final day of this snapshot. These comparisons describe trading volume; a larger number of shares traded does not establish a higher share price or a better investment return.

Back to top