To give you an example plotly comes with an inbuilt dataset called txhousing. try to run this code on your machine.
# lines -------------------------------------------------------------------
txhousing %>% setDT()
top5 <-
txhousing[, mean(sales, na.rm = T), city][order(-V1), ][1:5,]
txhousing %>% setkey(city)
top5 %>% setkey(city)
txhousing %>%
plot_ly() %>%
add_lines(
x = ~ date,
y = ~ median,
alpha = .2,
color = ~ city,
colors = 'black'
) %>%
add_lines(
data = (top5[txhousing][!is.na(V1),]),
x = ~ date,
y = ~ median,
color = ~ city,
colors = I('red'),
size = I(2)
) %>%
hide_legend() %>%
config(displayModeBar = F)
above code is meant to highlight top 5 cities in the data. and it is taken from the book
3 Scattered foundations | Interactive web-based data visualization with R, plotly, and shiny.
But I do not find any example where I could change the color of a current line.
now this code should plot another line on the top of the last line just like geom_line() does in ggplot2. but it doesn't the plot it produces is.
instead of changing the color to red it doesn't change color at all.
Is there a method to do that. or there something I am missing. I need this thing to create a different plot for shiny dashboard and it has to be interactive and fast. so I would rather choose a plot_ly alternative than to first plot it in ggplot2 and then change it to plotly.
Is there a any method. Please let me know.