# How to mimic \`dplyr::count()\` using only \`plotly\` transforms

**URL:** <https://community.plotly.com/t/how-to-mimic-dplyr-count-using-only-plotly-transforms/21905>\
**Category:** Plotly R\
**Created:** [April 4, 2019, 4:50pm UTC](https://community.plotly.com/t/how-to-mimic-dplyr-count-using-only-plotly-transforms/21905 "2019-04-04T16:50:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![robertmitchellv](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/robertmitchellv/32/6337_2.png) [@robertmitchellv](https://community.plotly.com/u/robertmitchellv)\
**Post date:** [April 4, 2019, 4:50pm UTC](https://community.plotly.com/t/how-to-mimic-dplyr-count-using-only-plotly-transforms/21905/1 "2019-04-04T16:50:55Z")

</div>

I’m trying to mimic `dplyr::count()` using only the aggregate transofrms from `plot_ly()` in R.

Rather than doing something like:

```auto
library(tidyverse)
library(plotly)

iris %>%
  count(Species) %>%
  plot_ly(...)

```

I want to do something like:

```auto
library(plotly)

plot_ly(
  data = iris,
  type = "bar",
  x = ~Species,
  y = ?????,
  mode = "markers",
  transforms = list(
    list(
      type = "aggregate",
      groups = ~Species,
      aggregations = list(
        list(
          target = "y", func = "count", enabled = T
        )
      )
    )
  )
)

```

How would I be able to accomplish this?

---

<div class="post-metadata">

**Author:** ![robertmitchellv](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/robertmitchellv/32/6337_2.png) [@robertmitchellv](https://community.plotly.com/u/robertmitchellv)\
**Post date:** [April 4, 2019, 6:07pm UTC](https://community.plotly.com/t/how-to-mimic-dplyr-count-using-only-plotly-transforms/21905/2 "2019-04-04T18:07:28Z")

</div>

In case anyone was curious, this seemed to work:

```auto
plot_ly(
  data = iris,
  type = "bar",
  x = ~Species,
  y = ~Species,
  transforms = list(
    list(
      type = "aggregate",
      groups = ~Species,
      aggregations = list(
        list(
          target = "y", func = "count", enabled = T
        )
      )
    )
  )
)

```
