Is there better way to:
- Get rid of for loops
- Remove legend and mark the line colors on the line itself elegantly ?
Please find the reprex below along with my attempt to make secondary axis.
library(tidyverse)
l = data.frame(L = integer())
l_aggr <- function(mydata){
for (j in 1:3){
for(i in 1:10){
l[i,j] = sum(i*j,j*i+1)
}
l = as.data.frame(l)
}
return(l)
}
l_aggr(1) %>%
gather(ax, va) %>%
mutate(year = rep(2000:2009,3)) %>%
ggplot(aes(x= year,y= va, col = ax)) +
geom_line() +
scale_y_continuous(sec.axis = ~.*2, "relative L")
Attempt for creating another axis
l_aggr(1) %>%
mutate(year = 2000:2009) %>%
ggplot(aes(x= year)) +
geom_line(aes(y=L, col = "L")) +
geom_line(aes(y=V2, col = "V2")) +
geom_line(aes(y=V3*.5, col = V3)) +
scale_y_discrete(sec.axis = ~.*2, "relative V3")