I use ggplot2 to create a point plot and then I add the correlation coefficient to that chart. Next, I use plotly to see info about each data point. However, there is a mistake in font style in the plot as shown here.
I need R = 0.87 and P = 2.2e-16, not "italic(R)" or "italic(P)", while keeping mapping part in stat_cor. I guess, plotly cannot understand italic(p) part as a code. The solution should not fix that adding a text manually, I need the calculation of "R" and "P".
Here is the code:
p1 <- ggplot(iris) +
geom_point(aes(Sepal.Length, Petal.Length)) +
stat_cor(mapping = aes(Sepal.Length, Petal.Length))
p2 <- ggplotly(p1)
p2
You can add anotations to the plotly chart - any sort of R functions and html code are going to work as part of the text.
Plotly only solution
A possible solution is using plotly directly, not using ggplot then converting.
The code would be:
Alternative using ggplotly
As you prefer to use ggplotly, the exact same annotation can be used on it. In this case, the code is: