Ste*_*one 5 r colors histogram plotly
我正在尝试绘制具有特定颜色的直方图,因为目的是从两个不同的数据帧创建两个直方图,并且我不想将它们都显示为默认的蓝色。我知道解决方案意味着将 ggplo2 对象转换为plotly,但我想找到一种方法来解决plotly代码中的这个小问题。基本绘图直方图的代码如下:
    plot_ly(x=~dataframe$variable, type="histogram") %>%
    layout(title="Histogram title", xaxis=list(title="X-axis title"))
我尝试过的两种解决方案均无效:
1)第一次尝试:
    plot_ly(x=~dataframe$variable, type="histogram", color="green") %>%
    layout(title="Histogram title", xaxis=list(title="X-axis title"))
它返回以下警告消息:
    In RColorBrewer::brewer.pal(N, "Set2") :
    minimal value for n is 3, returning requested palette with 3 different levels
2)第二次尝试:
    plot_ly(x=~dataframe$variable, type="histogram", colour="green") %>%
    layout(title="Histogram title", xaxis=list(title="X-axis title"))
它返回以下警告消息:
    'histogram' objects don't have these attributes: 'colour'
    Valid attributes include:
    'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'hoverinfo', 'hoverlabel', 'stream', 'x', 'y', 'text', 'orientation', 'histfunc', 'histnorm', 'cumulative', 'autobinx', 'nbinsx', 'xbins', 'autobiny', 'nbinsy', 'ybins', 'marker', 'error_y', 'error_x', '_deprecated', 'xaxis', 'yaxis', 'xcalendar', 'ycalendar', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'xsrc', 'ysrc', 'textsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule'
有什么建议么?
下面的情节可行吗?参数color必须指定给marker属性。
library(plotly)
set.seed(1)
dataframe <- data.frame(variable = rnorm(1000))
plot_ly(x=~dataframe$variable, type="histogram", marker = list(color = 'green')) %>%
  layout(title="Histogram title", xaxis=list(title="X-axis title"))