library(lubridate) library(ggplot2) ##Create an empty dataset to put all my data into alldata <- data.frame(Date=character(), perfperdollar=numeric(), ticker=character()) for (ticker in c("MCD", "TSLA", 'SPY')){ ##Download the data for each ticker mydata <- read.csv(paste0("https://query1.finance.yahoo.com/v7/finance/download/", ticker, "?period1=1693440000&period2=1699142400&interval=1d&events=history&includeAdjustedClose=true")) mydata$Date=ymd(mydata$Date) first=mydata[1,"Adj.Close"] mydata$perfperdollar=mydata$Adj.Close/first mydata <- mydata[, c("Date", "perfperdollar")] mydata$ticker=ticker; ##Put the data for this ticker in the big dataset alldata <- rbind(alldata, mydata) } ##Create the graph myplot <- ggplot(data=alldata)+ geom_path(aes(x=Date, y=perfperdollar, group=ticker, color=ticker)) ##Save the graph ggsave(myplot, file="p.png")