Does anyone know if it is possible to create a grouped bar chart using plotly? I am trying to create a graph similar to the one attached, and I can’t seem to figure out how to add a trace that allows for groups. I am trying to group my data so that each category (Furniture, Office supplies, and Technology) each have their own group of bars. If I leave out the color variable, and group it based on Category, it works, but it doesen’t really group it like the examples for bar charts on the R documentation for plotly. Thoughts?
Thanks so much!
Data for chart:
this data was a subset, but stored in a local dataframe.
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
barchart %>%
plot_ly(
x = Category,
y =Total Sales
,
type = “bar”,
group = SubCategory
)