R 如何使用颜色填充解决ggplotly错误

R 如何使用颜色填充解决ggplotly错误,r,ggplot2,plotly,R,Ggplot2,Plotly,使用从ggplot2扩展的ggplotly调用,我试图为点添加轮廓 对ggplot的调用有效,但将调用扩展到ggplotly会产生错误 目标是基于具有黑色轮廓的连续变量(在这种情况下使用pch=21),生成具有颜色填充点的交互式绘图 最小可重复示例: library(ggplot2) library(plotly) ggplot(data=mtcars, aes(mpg, wt, fill=hp))+geom_point(pch=I(21))+scale_fill_continuous(low=

使用从ggplot2扩展的
ggplotly
调用,我试图为点添加轮廓

ggplot
的调用有效,但将调用扩展到
ggplotly
会产生错误

目标是基于具有黑色轮廓的连续变量(在这种情况下使用
pch
=21),生成具有颜色填充点的交互式绘图

最小可重复示例:

library(ggplot2)
library(plotly)
ggplot(data=mtcars, aes(mpg, wt, fill=hp))+geom_point(pch=I(21))+scale_fill_continuous(low='red', high='blue')

错误:不知道如何将o添加到绘图中
此外:警告信息:

在L$MAKER$color[idx]中,您就快到了,但是不需要在
ggplot()
调用的末尾标记
+ggplotly()
,而需要用
ggplotly
包围
ggplot

## save the ggplot object 
g <- ggplot(data=mtcars, aes(mpg, wt, fill=hp))+
    geom_point(pch=I(21))+
    scale_fill_continuous(low='red', high='blue')

## call ggplotly on the ggplot object
ggplotly(g)
有关更多示例,请参见和


谢谢,正如您注意到的,输出没有正确显示填充颜色(全部为红色),错误消息仍然存在……我也是!是否可以使用base plotly根据因子添加填充?看起来更好。你能得到一个黑色轮廓的要点吗?冒着污染评论的风险,很好!
## save the ggplot object 
g <- ggplot(data=mtcars, aes(mpg, wt, fill=hp))+
    geom_point(pch=I(21))+
    scale_fill_continuous(low='red', high='blue')

## call ggplotly on the ggplot object
ggplotly(g)
pal <- colorRampPalette(c("red","blue"))(length(unique(mtcars$hp)))

plot_ly(data = mtcars, x = ~mpg, y = ~wt, color = ~hp, colors = pal, 
            type = "scatter", mode = "markers",
            marker = list(size = 10,
                          line = list(color = "black",
                          width = 2)))