plotly.R icon indicating copy to clipboard operation
plotly.R copied to clipboard

replicate ggplot2 text legend

Open ThierryO opened this issue 3 years ago • 1 comments

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

ggplot2 version

ggplotly version

ggplotly version

ThierryO avatar Apr 20 '22 13:04 ThierryO

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.

danttis avatar Apr 23 '22 12:04 danttis