Add legend to Plotly Graph R

Viewed 64

I would like assistance producing a legend for a plotly graph such as the one plotted as below:

myX = c(1:3);
myY = c(1:3);

        
p <- plot_ly() %>%
            add_trace(
                type = "scatter",
                mode = "markers+text",
                x = myX,
                y = myY,
                symbol = c(0:2),
                marker = list(line = list(width = 1.5)),
                symbols = c(0:2),
                size = 5,
                text = c("one", "two", "three"),
                textfont = list(size = 8),
                textposition = 'bottom center'
            )  

enter image description here

The legend would effectively relay the same information relayed by the marker text annotations. I would like to do this for i) the case where the legend is beside the plot and ii) the case where only the legend is rendered (i.e. without a plot).

0 Answers
Related