Posted on:

29 Feb 2024

0

2st Line Chart by R- (Warning message)

Hi Eli,
I got this 

( Warning message:
Removed 5262 rows containing missing values (`geom_line()`).  )

library(ggplot2)
library(plyr)
library(reshape2)


df_spx_ftse_2010_2020 <- read.csv("returns1020.csv",
                                  header = TRUE,
                                  sep = ",")

df_spx_ftse_2010_2020$Date <- as.Date(df_spx_ftse_2010_2020$Date,
                                      format = "%m/%d/%y")

df_spx_ftse_2010_2020_melt <- melt(df_spx_ftse_2010_2020,
                                   id = "Date")

df_spx_ftse_2010_2020_melt <- rename(df_spx_ftse_2010_2020_melt,
                                     c("value" = "Returns",
                                       "variable" = "Index"))

line_chart <- ggplot(df_spx_ftse_2010_2020_melt,
                     aes(x= Date,
                         y= Returns,
                         colour = Index,
                         group = Index)) +

            geom_line(aes(color = Index),
                      size = 1) + 
            scale_color_manual(values = c("#050B7D","#FC811D")) +
            theme_minimal() +  
            ggtitle("S&P vs FTSE Returns (2000 - 2010")
                     
line_chart




min <- as.Date("2015-7-1")
max <- as.Date("2016-12-31")

line_chart_H2_2015 <- ggplot(df_spx_ftse_2010_2020_melt,
                     aes(x= Date,
                         y= Returns,
                         colour = Index,
                         group = Index)) +
  
  geom_line(aes(color = Index),
                size = 1) + 
  scale_color_manual(values = c("#050B7D","#FC811D")) + 
  theme_minimal()  +
  ggtitle("S&P vs FTSE Returns (H2 2015)") +
  
  scale_x_date(limits = c(min, max)) 
  


line_chart_H2_2015

 

0 answers ( 0 marked as helpful)

Submit an answer