narnia649
narnia649

Reputation: 381

How to turn off a specific legend type within plotly & R Language?

I created a plot using ggplot() and turned off linetype part of the legend using "+ guides(linetype=False)".

However, when I use the ggplotly() function it completely overrides this and still displays the linetype in the legend. My thought was I need to remove that part of the legend for the generated plotly object, but I wasn't sure how to just remove the linetype within the plotly object (p object below). I do want to keep the color legend.

An example dataset to be plotted:

library("ggplot2")
library("plotly")

dataset = read.csv("file_loc")

g = ggplot(data=dataset) +
geom_line(x=dataset$Time,
y=dataset$Values,
group=dataset$group,
linetype=dataset$group,
color=dataset$Othervalue) +

# Doesn't work when using ggplotly function
guides(linetype=FALSE)

p = ggplotly(g)

Note: I am using R version 3.6.0, ggplot2 3.3.5, plotly 4.9.4.1

Upvotes: 1

Views: 796

Answers (1)

narnia649
narnia649

Reputation: 381

I found that if I turn off the legend for p or p=layout(p,showlegend=FALSE) it turns off just the plotly legends but keeps the ggplot legends previously hidden or kept.

Upvotes: 0

Related Questions