Skip to content

limits of geom_histogram in a loop #24

Answered by almenal
ZahraEM77 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Zahra!

Sure, there is a way! The way you specify an x-axis range in ggplot is by using the family of functions scale_x_*, in this case you'll need to use scale_x_continuous(). Since you'll want the same limits for each gene, you can move the inner-most loop to the top, so that you can calculate the range of a gene first, and then apply it to all plots

In case it wasn't clear, your current loop is like this:

for (m in all_method ){
  ...
  for (s in all_sorted){
    ...
    for (g in all_genes){
      }
   }
}

so you should move the for (g in all_genes){ to the top. You can do the same thing you're doing of filtering dataframes sequentially to get a dataframe with only gene g.
Once you…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@ZahraEM77
Comment options

@almenal
Comment options

almenal Jul 2, 2021
Collaborator

@ZahraEM77
Comment options

Answer selected by valegiunchiglia
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants