plotly.R
plotly.R copied to clipboard
replicate ggplot2 text legend
I'd like to create a legend having text over a point as in the ggplot2 example below. How can I replicate this with plotly. Doesn't need to be a nice and clean ggplotly() solution.
library(ggplot2)
library(plotly)
ds <- data.frame(text = c("+", "-"))
p <- ggplot(ds, aes(x = text, y = text, label = text)) +
geom_point(aes(colour = text), size = 6) +
geom_text(show.legend = TRUE) +
guides(colour = guide_legend(override.aes = list(label = c("-", "+")))) +
scale_colour_discrete(labels = c("minus", "plus"))
p
ggplotly(p)
ggplot2 version

ggplotly version

a solution would be to put create a name vector and put names <-c("minus", "plus"), and pass in the geom_point(aes(colour = text, shape=names) argument, but I'm not sure if that's what you want.