Hello everyone,
I would like to ask you how can I get the number of exon? I want visualize gene length vs. number of exons in gene.

For example:

I have the length of the gene:

    exons <- getBM(attributes = c("external_gene_name","start_position","end_position","ensembl_exon_id"),
              filters = "chromosome_name",
              values = "21",
              mart = genes)
    exons[5] <- exons$end_position - exons$start_position
    names(exons)[5] <- "gene_length"

I tried to find out the number of exons:

    as.data.frame(table(exons$ensembl_exon_id))

But now, I don't know what else. Please, somebody would help me? 
Something like :

    require(tidyverse)
    genes <- useDataset("hsapiens_gene_ensembl",mart=ensembl)
    exons <- getBM(attributes =
          c("external_gene_name","start_position","end_position","ensembl_exon_id"),
          filters = "chromosome_name",
          values = "21",
          mart = genes)
    exons <- as.tibble(exons)
    exons.plot <- exons %>% 
        mutate(len=end_position-start_position) %>% 
        group_by(external_gene_name) %>% 
        summarize(geneLen=sum(len),exonNumber=n())
    # plot
    ggplot(exons.plot,aes(x=geneLen,y=exonNumber))+
      geom_point(alpha=0.5)+
      scale_y_log10()+
      scale_x_log10()+
      theme_bw()

FYI you should use ensembl_gene_id instead of gene name

![enter image description here][1]


  [1]: https://image.ibb.co/byyCpb/Rplot02.png