Skip to content

Opacity in Grouped Bar Charts with data.frame  #1666

Open
@roberthinch

Description

@roberthinch

When plotting a grouped bar chart with variable opacity with data in a data.frame, the opacity assigned to each column is not the one specified in the data.frame. In the example below, the 2 bars in group "A" are plotted with reduced opacity, as opposed to the 2 bars with colour "C". Strangely, if the data.frame is not ordered then it plots correctly.

library( plotly )

data  = data.frame( 
  x      = c( "A", "B", "A", "B" ),
  y      = c(   1,   2,   3,   4 ),
  z      = c( "C", "C", "D", "D" ),
 opacity = c( 0.3, 0.3,   1,   1 )
)

# removing this lines the plot is correct
data = data[ order( data$x ),]

p = plot_ly( 
  data   = data, 
  x      = ~x, 
  y      = ~y, 
  color  = ~z, 
  marker = list( opacity = ~opacity ),
  type   = "bar" ) %>% 
layout( barmode = "group" )
show( p )

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions