Hi all the below code is working fine. But there is a need to split the plot into 2 as per categories in Cat column (A and B)
Can we split the graphs here
goals <- data.frame(Year = c(2017, 2018, 2019, 2017, 2018, 2019, 2017, 2018, 2019 ),
Number= c(47, 35, 40, 49, 32, 31, 51, 49, 44 ),
Week = c(1,1,1, 2, 2, 2, 11,11,11),
Cat = c("A","B","A", "B", "A", "B", "A","B","A")
)
goals <- goals[order(goals[,"Week"],goals[,"Year"]),]
goals$Week <- as.factor(goals$Week)
goals$Year <- as.factor(goals$Year)
goals1 <- data.frame(Year = c(2017, 2018, 2019, 2017, 2018, 2019, 2017, 2018, 2019),
Number1= c(46, 45, 45, 65, 32, 56, 32, 12, 43 ),
Week = c(1,1,1, 2, 2, 2, 11,11,11),
Cat = c("A","B","A", "B", "A", "B", "A","B","A")
)
goals1 <- goals1[order(goals1[,"Week"],goals1[,"Year"]),]
goals1$Week <- as.factor(goals1$Week)
goals1$Year <- as.factor(goals1$Year)
# df <- tibble::tibble(Date, Values)
# df2 <- tibble::tibble(Date2, Values2)
testfunction <- function(x, y, x2, y2) {
x <- enquo(x)
y <- enquo(y)
x2 <- enquo(x2)
y2 <- enquo(y2)
plot_ly(goals, x = x, y = y, type = "scatter", mode = "lines",color = ~Year)%>%
add_trace(x = x2, y = y2, data = goals1,yaxis = "y2", line = list(width = 2, dash = 'dash'))%>%
layout(yaxis2 = list(overlaying = "y", side = "right")) %>% layout(hovermode = 'compare')
}
testfunction(Week, Number, Week, Number1)