I am trying to make a correlation plot with plot_ly
As an example I do
library(plotly)
d <- diamonds[sample(nrow(diamonds), 1000), ]
p <- plot_ly(
d, x = ~carat, y = ~price,
# Hover text:
text = ~paste("Price: ", price, '$<br>Cut:', cut),
color = ~carat, size = ~carat
)
then plot
but how can I make the linear line and calculate the R2? is there a way to do it?
If you know any other way to do it, please let me know.
For example, something like this would be great
[![enter image description here][1]][1]
http://vault.hanover.edu/~altermattw/courses/220/R/corr/corr_2.html
I tried to do it with:
library(ggplot2)
ggplot(d, aes(x=carat, y=price)) +
geom_point(aes(colour = Outcome)) +
geom_smooth(method=lm)
which I am getting an error.