Multiple entries in legend from subplot stacked barplot

I have a problem with a plot with a number of subplots, which all have the same legend entries. I want to show the legend entries only once for each color/name. How can I avoid this behaviour?


mpg %>%
  group_by(class) %>%
  do(p = plot_ly(., x = ~cyl, y = ~displ, color = ~trans, type = 'bar')) %>%
  subplot(nrows = 2, shareX = TRUE, titleX = TRUE) %>%
  layout(barmode = 'stack')