getwd()
dir()
dat <- read.delim("nvidia.csv", header = TRUE, sep = " ")
head(dat)

## Go make a graph
# we started with a time-series bar graph, so should probably make a line graph
# colors are hard to distinguish
# grid is distracting
# background fades unnecessarily

## base R or ggplot?
library(ggplot2)
# I wanted to do base R.

## what kind of graph?
# A scatterplot, then a line graph
ggplot(dat, mapping = aes(x = Year, y = Sales)) + geom_point() + geom_line()

# We have to be really careful here. Sales for 2026 and 2027 are mere projections. We need to emphasize that. Let's create a "Type" column, with only 7 rows we can write it, but could duplicate "Year" and replace relevant ranges by our desired entry. Or duplicate the "Sales" column and, knowing the data, set all values about "200" to "Projected".

dat$Type <- c(rep("Actual", 5), rep("Projected", 2))
dat
# it worked

# We will code redundantly the point shape and color using "Type". Note the break in the sales, which is a nice reinforcement of the "Actual" and "Projected" data.
ggplot(dat, mapping = aes(x = Year, y = Sales, shape = Type, color = Type)) + geom_point() + geom_line()

# Given all that we've discussed, it's worth considering removing the legend in favor of direct labeling. We should probably explore themes that exchange the white-on-gray background grid for something less distracting.

install.packages("directlabels")
library(directlabels)

# you can sselectively suppress legends, ...
ggplot(dat, mapping = aes(x = Year, y = Sales, shape = Type, color = Type)) + geom_point(show.legend = FALSE) + directlabels::geom_dl(aes(label = Type), method = "smart.grid") + geom_line(show.legend = FALSE)

# ... or turn them off all at once
ggplot(dat, mapping = aes(x = Year, y = Sales, shape = Type, color = Type)) + geom_point() + directlabels::geom_dl(aes(label = Type), method = "smart.grid") + geom_line() + theme(legend.position = "none")

# never make someone turn their head sideways (if you can avoid it)
ggplot(dat, mapping = aes(x = Year, y = Sales, shape = Type, color = Type)) + 
  ylim(0, 350) + 
  geom_point() + 
  directlabels::geom_dl(aes(label = Type), method = "smart.grid") + 
  geom_line() + 
  labs(x = "", y = "", colour = "", title = "Nvidia expects $312 billion in revenues in 2027", subtitle = "Up from $16.7 billion in 2021") + 
  theme_classic() + 
  theme(plot.title = element_text(face = "bold", size = 12), legend.position = "none")

# Notice how the theme "theme_<name>()" styles the axis - counter to what we discussed today.