Making NBA Season Years a date or numerical


I am trying to make a plot about Three Point Percentages in the NBA. NBA seasons are always between two years (i.e. 2000-2001) but I don't know of a current way to make that year range a date or numerical so I can make them the x axis of my plot. Is this possible in R?

You can extract the first four characters of the text and make it a number.

DF <- data.frame(Season = c("2000-2001","2001-2002","2002-2003"))
DF$StartYear <- as.numeric(substr(DF$Season, start = 1, stop = 4))
     Season StartYear
1 2000-2001      2000
2 2001-2002      2001
3 2002-2003      2002

[1] "numeric"

Welcome to the community @yeet! It is possible to plot the seasons on the x-axis as character values (example below). Is there a specific need to change them to date or numeric?


# sample data
df = data.frame(
  season = c('2020-2021', '2021-2022', '2022-2023'),
  three_pct = c(0.44, 0.41, 0.48)

ggplot(df, aes(season, three_pct)) + 
  geom_bar(stat = 'identity')

Created on 2023-01-29 with reprex v2.0.2.9000

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.