I am trying to plot a histogram with a specific colour since the purpose is to do create two histograms from two different data frames and I do not want to present both of them with the default blue colour. I am aware that a solution would imply the conversion of the ggplo2 object into plotly, but I would like to find out a way to solve this small problem in the plotly code. The code for a basic plotly histogram is the following:
plot_ly(x=~dataframe$variable, type="histogram") %>%
layout(title="Histogram title", xaxis=list(title="X-axis title"))
The two solutions I have tried do not work:
1) First attempt:
plot_ly(x=~dataframe$variable, type="histogram", color="green") %>%
layout(title="Histogram title", xaxis=list(title="X-axis title"))
It returns the following warning message:
In RColorBrewer::brewer.pal(N, "Set2") :
minimal value for n is 3, returning requested palette with 3 different levels
2) Second attempt:
plot_ly(x=~dataframe$variable, type="histogram", colour="green") %>%
layout(title="Histogram title", xaxis=list(title="X-axis title"))
It returns the following warning message:
'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'
Any suggestions?
Does the plot below work? The color
argument must be specified to the marker
attribute.
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"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With