У меня есть данные для одного и того же достоверного на разных глубинах. Данные были взяты ежемесячно.
Я хочу построить все месяцы на одном графике. Я хочу, чтобы цвета менялись в зависимости от глубины.
Проблема: в функции цвета меняются в зависимости от месяца
Months$Month <- as.numeric(as.factor(Months$Month)) #Transform months to numbers, need to make it number equal to month name NOW THE NUMBERS START WITH 1 AND SHOULD START WITH 3(MARCH) PROBLEM
Seasonality <- function(Data = Months, Station, nut = c("NH4", "NO2", "NO3", "NOx", "DSi", "PO4"), col = "black") {
Site <- Data[Data$Site == Station, ] # Subset per station
Depths <- unique(Site$Depth) # Selects each depth
Mont <- unique(Site$Month)
for (n in 1:length(nut)){
Nutname <- nut[n]
plot(y = Site[,Nutname], x = Site$Month, type = "n",
main = Nutname, cex.main = 0.9, cex.lab = 0.9,
ylab = "umol/L", xlab = "Month", bty = "l")
#This is the easy way of plotting the charts but colors do not work!!!
# for (r in Depths){
# cols = c("aquamarine", "cyan", "darkturquoise", "deepskyblue", "dodgerblue", "blue4", "black")
# Dep <- subset(Site, Depth == r)
# with (Dep, lines(y = Dep[,Nutname], x = Mont, col = cols, type = "b", pch = 19)) #I cant make the colours work per line
# }
#This is th complicated way but this allows me to have different colours
lines(y = Site[,Nutname][Site$Depth == 0], x = Mont, type = "b", col = "aquamarine", pch = 0)
lines(y = Site[,Nutname][Site$Depth == -1], x = Mont, type = "b", col = "cyan", pch = 1)
lines(y = Site[,Nutname][Site$Depth == -2], x = Mont, type = "b", col = "darkturquoise", pch = 2)
lines(y = Site[,Nutname][Site$Depth == -3], x = Mont, type = "b", col = "deepskyblue", pch = 3)
lines(y = Site[,Nutname][Site$Depth == -5], x = Mont, type = "b", col = "dodgerblue", pch = 4)
lines(y = Site[,Nutname][Site$Depth == -10], x = Mont, type = "b", col = "blue4", pch = 5)
lines(y = Site[,Nutname][Site$Depth == -14], x = Mont, type = "b", col = "black", pch = 6)
mtext (outer = TRUE, side = 3, Station, cex = 2)
}
legend("topright", col = c("aquamarine", "cyan", "darkturquoise", "deepskyblue", "dodgerblue", "blue4", "black"), pch = c(1,2,3,4,5,6), c("0", "-1", "-2", "-3", "-5", "-10", "-14"), bty = "n", title = "Depth")
}
Stats <- unique(Months$Site)
par(mfrow = c(2,3), xpd = TRUE, oma = c(4,4,4,4))
for (i in 1:length(Stats))
Seasonality(Station = Stats[i])
Я пробовал много вещей, но понятия не имею, как это исправить