I get the following error when I use grid.arrange:
Error: Aesthetics must be either length 1 or the same as the data (3): x, y
Please see a sample data below. I need for each value in column Security_Ticker create a graph where x = Period and y = Price and show all graphs in one panel with four graphs in a row.
df <- read.table(text = "Security_Ticker Period Price
aapl 201901 100
goog 201902 200
nvda 201901 150
aapl 201902 110
goog 201903 220
nvda 201902 155
aapl 201903 250
goog 201904 280", header =TRUE)
df.splitted= split(df,df$Security_Ticker)
plot_list = list()
for(i in 1:length(df.splitted)){
p <- ggplot(data=df.splitted[[i]],aes(x=df.splitted[[i]][[2]], y=df.splitted[[i]][[3]])) + geom_line() + ggtitle(df.splitted[[i]][[1]][1])
plot_list[[i]] = p
print(p)
}
grid.arrange(plot_list,ncol=4)
I need to print all graphs from the plot_list in one panel with 4 graphs in a row, but I get the following error: Error: Aesthetics must be either length 1 or the same as the data (3): x, y
I know it should be easy to fix, but I have no experience with it.