Error Wrapping in ggplotly()

Hi,

When I run the following code;

library(magrittr)
library(ggplot2)
library(plotly)


plotly_speed1 <- datasets::mtcars %>% 
  as.data.frame() %>% 
  ggplot(aes(x = wt, y = mpg, color = factor(am)))+
  geom_smooth(formula = y ~ x,
              method = "lm", 
              se = FALSE,
              color = "#4C787E") + 
  labs(title = "Speed vs Weight",
       y = "Speed (mpg)",
       x = "Weight (1000 lbs)")+
  theme(plot.title = element_text(hjust = 0.5),
        legend.position = c(0.88, 0.875),
        legend.background = element_blank())+
  geom_point()+
  geom_jitter() 

# print plot
plotly_speed1

# does not work if wrapped this way
plotly_speed1 %>%
  ggplotly(tooltip = all)

I get the error;

Error in match(x, table, nomatch = 0L) : 
  'match' requires vector arguments
> 

Kindly help me figure out what the issue is.

The above code runs when I wrap the ggplot2 object like this:

# works is if wrapped this way;
ggplotly(plotly_speed1)

Or like this;

# works is if wrapped this way
plotly_speed1 %>%
  ggplotly()

So that is the solution.

without quotes all would need to be some object in R, try ...

plotly_speed1 %>%
  ggplotly(tooltip = "all")

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.