Create and histogram for transcripts per gene

Hello I have to do a project with the following instruction :
Plot the distribution of the number of transcripts per gene.
By distribution, we expect the density or binned histogram of the univariate number of transcript per gene.

For the moment I did this, but this does not work very well ...

library(dplyr)
library(tidyverse)
library(ggplot2)
library(forcats)
gencode %>%
  filter(!is.na(transcript_id)) %>%
  group_by(gene_id) %>%
  summarise(n = n_distinct(transcript_id)) %>%
  ggplot(aes(x = gene_id)) +
  stat_bin(aes(y = "count", label= "count"), geom="text", vjust=-.5) +
  geom_bar(stat="identity")
  geom_histogram(aes(x = n), 
                 col ="red", 
                 fill = "green", 
                 alpha = .2) + 
  geom_density(col = 2) + 
  labs(title = "Histogram of transcript per gene", x = "gene", y = "transcript")

I would be happy if you could help me, thanks a lot

Hi, welcome!

Please have a look to our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

Also, please understand that your code can not be run without suitable data, which is private to you.
look into the following guide for general advice how to overcome such an issue

Finally., you write that your code 'does not work very well', but I think you should be more specific about your issues with it.

I'm very sorry about this actually i modified the instructions so they are not word for word the same but I will not do this anymore, the problem is that is shows mee that stat_bin() needs an astehtic x or y axe an I don't know what to do...

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.