I am trying to plot the loess fit curves in each of sub-figures. There are three models and each model will have a color to represent. The code to generate the plot is as follows,
mydata1 <- data.frame("model" = rep("A", 1000), "n" = sample.int(10, 1000, replace = T), "n1" = seq(1,1000), "values" = rnorm(1000))
mydata2 <- data.frame("model" = rep("B", 1000), "n" = sample.int(10, 1000, replace = T), "n1" = seq(1,1000), "values" = rnorm(1000))
mydata3 <- data.frame("model" = rep("C", 500), "n" = c(rep(6,100),rep(7,100),rep(8,100),rep(9,100),rep(10,100)), "n1" = seq(1,500), "values" = rnorm(500))
mydata <- rbind(mydata1, mydata2, mydata3)
fig_list <- list()
for (i in sort(unique(mydata$n))) {
data <- mydata[mydata$n == i, ]
fig_list[[i]] <- ggplot(data, aes(x = n1, y = values, colour = model)) +
geom_point(size = 0.6, show.legend = TRUE) +
scale_color_discrete(limits = unique(mydata$model)) +
labs(title = paste0("n = ", i), x = "n1", y = "values") +
theme(plot.title = element_text(hjust = 0.5, size = 10)) +
geom_smooth(method = "loess", span = 0.3, fill = "lightskyblue", level = 0.95)
}
fig_all <- ggarrange(
plotlist = fig_list, ncol = 2, nrow = ceiling(length(fig_list) / 2),
common.legend = TRUE, legend = "top"
)
annotate_figure(fig_all, top = text_grob(paste0("All the plots are here.")))
However, if I use the code above, the legend of the models are mixed with lines and point, while I want all three to show points of different color. How can I unify the legend to show three models with points rather than mixed lines and point?