I am trying to create a grouped bar chart in plotly, but I cannot seem to color my bars within a group(so they are all the same color). Does anyone know how to do this in plotly? I would like to color my barchart according to the SubCategory(so all bars in a sub-category have their own color). I have tried adding traces to a graph, but no luck. Thanks.
sample <- data.frame(
Category <- c("Furniture","Furniture","Furniture","Furniture",
"Office Supplies","Office Supplies", "Office Supplies", "Office Supplies",
"Office Supplies", "Office Supplies", "Office Supplies", "Office Supplies",
"Office Supplies", "Technology","Technology","Technology","Technology"),
SubCategory <- c("Bookcases","Chairs","Furnishings","Tables","Appliances","Art","Binders","Envelopes",
"Fasteners","Labels","Paper","Storage", "Supplies", "Accessories","Copiers","Machines",
"Phones"),
sales <- c(889222.51,920892.65,239840.16,445823.93,614737.91,225594.68,281494.68,104903.88,50156.06,44269.30,
150113.36,692903.08,152196.19,463383.33,965899.78,458655.43,1005525.38)
)
#plot code so far
sample %>%
plot_ly(
x = Category,
y = sales,
type = "bar",
group = SubCategory
)
Below is what I have so far, but the coloring is not based on the grouping. When I supply a color variable, it does not color all the bars within the SubCategory the same color. Is this is possible bug?
ggplotly()
actually but there are spaces between the bars forfurniture
andtechnology
because they don't have as many subcategories asoffice supplies
. – Cyrus Mohammadian