I pulled some data from Fama French web site on operating data by month...here is my code that works (below).
I have 7 columns of data, with headers, including Date. I have successfully graphed one column data, but I would like to add several of the other columns of data to my chart with colors, and I'm struggling to add the additional columnar data. Suggestions? Thank you.
Here is code for computing a yearly average for each variable. The dates were coming in as integers, so I extracted the year by truncating the date/100
library(tidyverse)
df <- read.csv("~/R/Play/Dummy.csv")
ByYear <- df |> select(Date, SMALL_LoOP, ME1_OP2, ME1_OP9, SMALL_HiOP, BIG_LoOP, BIG_HiOP) |>
pivot_longer(cols = -Date, names_to = "Variable", values_to = "Value") |>
mutate(Year = trunc(Date/100)) |>
group_by(Year, Variable) |>
summarize(Avg = mean(Value, na.rm = TRUE))
#> `summarise()` has grouped output by 'Year'. You can override using the
#> `.groups` argument.
ggplot(ByYear, aes(x= Year, y = Avg, color = Variable)) + geom_line() +
scale_x_continuous(breaks = 1963:1965)