I want to save the colours that automatically ggplot function assing to each station in a plot. I want to save the colour assigned to each station in a palette that I can reuse again in others plot:
ggplot(DSF_moments, aes(x=year, y=max, group = station, colour = station)) +
geom_line(size = 1) +
geom_point(size=1.5, shape=21, fill="white") +
labs(y ="Annual max flow [m3/s]", x = "year", title = "Annual Maximum Streamflow", size = 50) +
theme(plot.title = element_text(size=16), axis.text.y = element_text(size=11), axis.text.x = element_text(angle = 90, size=11)) + scale_x_continuous (breaks=seq(min(DSF_moments$year),max(DSF_moments$year),by=2)) +
scale_y_continuous (breaks=seq(min(DSF_moments$max),max(DSF_moments$max),by=5000))
dev.copy(png,"Plot_Max_Annual_RawData.png",width=22,height=11,units="in",res=100)
dev.off()
Using the colour function in the code above, ggplot assign a colour to each station, I do not want to change the colours, I only want to know which colour is assigned to each station. The idea is to generate after a plot separately for each station but maintaining the colours previously assigned in the first common plot with all the stations.
for (i in 1:length(listDF2))
{
df1 <- as.data.frame(listDF2[[i]])
df1[is.na(df1)] <- 0
temp_plot <- ggplot(df1, aes(x = day, y = DailyMeanStreamflow, colour=Station[i])) +
geom_line(size = 1) +
geom_point(size=1.5, shape=21, fill="white") +
facet_wrap(~ month, ncol = 3) +
labs(title = "Daily Mean Streamflow",
subtitle = "Data plotted by month",
y = "Daily Mean Streamflow [m3/s]", x="Days") +
scale_x_continuous (breaks=seq(1,max(df1$day),by=1)) + theme(axis.text.x = element_text(size=9))
print(temp_plot)
name4<- paste("DailyStreamflow_byMonth","_", siteNumber[i], ".png", sep="")
ggsave(temp_plot,filename = name4,width=22,height=11,units="in",dpi=500)
dev.off()
}
I want to assign now to each graph the colour assigned previously. How can I save the assigned default colours by ggplot to each station?
Stations are in format chr: "094985005","09498501","09489500"