I randomly simulated this time series data:
n_obs = 1:100
a1 = rexp(100,5)
b1 = rexp(100,5)
a1_col = "red"
b1_col = "blue"
symbol <- c("square","triangle")
point_symbol <- sample(symbol, 100, replace=TRUE, prob=c(0.5, 0.5))
stock_data = data.frame(n_obs, a1, b1, a1_col, b1_col, point_symbol)
stock_data$point_symbol_color = ifelse(stock_data$a1 > stock_data$b1, "hollow", "dark")
I was able to make a graph of this data:
library(ggplot2)
ggplot() +
geom_line(data = stock_data, aes(x = n_obs, y = a1), color = "red") +
geom_line(data = stock_data, aes(x = n_obs, y = b1), color = "blue") +
xlab('n_obs') +
ylab('exp value') + ggtitle("sample")
Is it possible to change the "shape" of each point according to the symbols I indicated above? I think this can be done with the following commands (https://www.datanovia.com/en/blog/ggplot-point-shapes-best-tips/) - but I am not sure how to add it to my existing plot:
Is it possible to change the "shading/fill" of the squares/triangles based on the "hollow"/"dark" values I have specified?
I think this can be done like this (I couldn't find the exact "hollow"/"dark" values here:https://ggplot2.tidyverse.org/reference/geom_point.html)
geom_point(shape = ifelse(stock_data$point_symbol == "square", 0,2) , fill = ifelse(stock_data$point_symbol_color == "hollow", "hollow", "dark"), color = "black", size = 3) - but I am not sure how to add this to the plot I made.
Is it also possible to add a legend to this plot?
- "a red line" = a1
- "a blue line" = b1
- "a square symbol" = square
- "a triangle symbol" = triangle
Thank you!

