Here is how you can build it with visibility of 'B' altered.
df1 <- data.frame(cat = rep(c("A","B","C"),10),
x = rnorm(30),
y = rnorm(30)) %>% arrange(x)
p <- plot_ly(width=400,
color =~cat) %>% add_lines()
df2 <- pivot_wider(df1,
names_from = cat,
values_from = y,
names_prefix = "y_"
) %>% arrange(x)
p2 <- plot_ly(width=400,
add_trace(y=~y_A, name="A",mode="lines", connectgaps = TRUE) %>%
add_trace(y=~y_B, name="B",mode="lines", connectgaps = TRUE,visible="legendonly") %>%
add_trace(y=~y_C, name="C",mode="lines", connectgaps = TRUE)