Using the ggplotly
call extending from ggplot2, I'm trying to add an outline to the points.
The call to ggplot
works, but extending the call to ggplotly
yields an error.
The objective is the have an interactive plot with color filled points based on a continuous variable with a black outline (using
pch
=21 in this case).
Minimal reproducible example:
library(ggplot2)
library(plotly)
ggplot(data=mtcars, aes(mpg, wt, fill=hp))+geom_point(pch=I(21))+scale_fill_continuous(low='red', high='blue')
ggplot(data=mtcars, aes(mpg, wt, fill=hp))+geom_point(pch=I(21))+scale_fill_continuous(low='red', high='blue')+ggplotly()
Error: Don't know how to add o to a plot
In addition: Warning message:
In L$marker$color[idx] <- aes2plotly(data, params, "fill")[idx] :
number of items to replace is not a multiple of replacement length
You're almost there, but instead of tagging on
+ggplotly()
on the end of theggplot()
call, you need to surround theggplot
withggplotly
Although, I am noticing that the
fill
isn't respected when callingggplotly
...To do this directly in
plot_ly
, you can specify a colour palette and plot itSee here and here for more examples