Skip to content

Not able to show Regression Line Equation using ggplotly #1687

Closed
@romabhu

Description

@romabhu

I need to display Regression Line Equation with the lineplot. I am using "stat_poly_eq" function present in "ggpmisc" package. Able to achieve it with ggplot (Find attached screenshot). But when when I am trying to show plot using ggplotly regression equition is getting disppeared (Find attached screenshot)

Below is the sample code, I am using:

library(ggplot2)
library(ggpmisc)
library(plotly)
df <- data.frame(x = c(1:100))
df$y <- 2 + 3 * df$x + rnorm(100, sd = 40)
my.formula <- y ~ x
p <- ggplot(data = df, aes(x = x, y = y)) +
geom_smooth(method = "lm", se=FALSE, color="black", formula = my.formula) +
stat_poly_eq(formula = my.formula,
aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")),
parse = TRUE) +
geom_point()
print(p)
ggplotly(p)

Please suggest probable solution with which i can achieve this. It is really urgent for me to show quation using ggplotly.
ggplotly_screenshot
ggplot_screenshot

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions