✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
🐇 Announcing Dash VTK for 3d simulation graphics. Check out the March webinar.

Keeping dot size fixed on scatterplot

Hello,

I followed https://dashr.plotly.com/layout. The dot size changes every time when zooming in or out. I would like to keep the dot size fixed when zooming in and out of a plot.

Is there an option to do that?

library(dash)
library(dashCoreComponents)
library(dashHtmlComponents)

app <- Dash$new()

df <- read.csv(
  file = "https://raw.githubusercontent.com/plotly/datasets/master/gapminderDataFiveYear.csv",
  stringsAsFactor=FALSE,
  check.names=FALSE
)

continents <- unique(df$continent)

data_gdp_life_exp_2007 <- with(df,
  lapply(continents,
         function(cont) {
           list(
             x = gdpPercap[continent == cont],
             y = lifeExp[continent == cont],
             opacity=0.7,
             text = country[continent == cont],
             mode = 'markers',
             name = cont,
             marker = list(size = 15,
                           line = list(width = 0.5, color = 'white'))
           )
         }
  )
)

app$layout(
  htmlDiv(
    list(
      dccGraph(
        id = 'life-exp-vs-gdp',
        figure = list(
          data =  data_gdp_life_exp_2007,
          layout = list(
            xaxis = list('type' = 'log', 'title' = 'GDP Per Capita'),
            yaxis = list('title' = 'Life Expectancy'),
            margin = list('l' = 40, 'b' = 40, 't' = 10, 'r' = 10),
            legend = list('x' = 0, 'y' = 1),
            hovermode = 'closest'
          )
        )
      )
    )
  )
)

app$run_server()

Hi @schienstockd welcome to the forum! This is not possible at the moment but I’ve created an issue for this in https://github.com/plotly/plotly.js/issues/4838. If someone from an organization with a software budget is interested in this feature, feature development can be accelerated with sponsoring :-).

If you really need circle markers which have a shape defined in data units, you could use shapes (possibly in combination with a trace with transparent markers if you want to have hover information).

Sounds good. The shapes would work for me.
I would like to display these shapes (derived from image segmentation) on images.

Is there a way to make these shapes editable?

I found the documentation for the python plotly version:

fig.add_shape(editable=True,
              x0=-1, x1=0, y0=2, y1=3,
              xref='x1', yref='y1')

My naive attempt to do this in R did not work.

fig <- fig %>% add_trace(
  x = c(0, 0, 100, 100),
  y = c(0, 100, 100, 0),
  type = 'scatter',
  fill = 'toself',
  fillcolor = '#e763fa',
  opacity = 0.5
  # editable = TRUE # ?
)

Is there a way to do this in dashr?

The editable attribute for shapes has just been added to plotly.js 1.54 and plotly.py 4.7 but it is not yet available in plotly R. However there is a config attribute editable=True to be able to edit all shapes.

Can I extract the datapoints that are within a shape? - In the same way as you can get the data points from ‘Box Select’?

Can I get the coordinates of the shapes as you have shown with dash-canvas?