Skip to contents

By default, Plotly only creates legend on the right - use to modify position and label accordingly

Usage

plotly_legend(fig, lg_pos = "bottom", lg_lab = "", dir = "h")

Arguments

fig

Plotly or subplot object as input (with ggplot legend position none)

lg_pos

Legend Position. Values: "right","left","top","bottom", c(1,2), c(5,7) etc

lg_lab

Legend Title Text; if any.

dir

Direction of legend. Values: "h", "v", "horizontal", "vertical"

Value

Plotly object with legend positioned and titled according to input

Examples

library(ggplot2)

g <- ggplot(iris, aes(x = Petal.Length, y = Petal.Width, color = Species)) +
  geom_point() +
  theme(legend.position = "none")
plotly_legend(plotly::ggplotly(g), "bottom", "Species:")