2 separate histograms from two separate datalists

> datalist
$A
# A tibble: 10 x 2
        O          G
   <dbl> <chr> 
 1     3       A     
 2     4       A     
 3     4       A     
 4     3       A     
 5     2       A   

$B
# A tibble: 10 x 2
        O      G
   <dbl> <chr> 
 1     5       B     
 2     5       B     
 3     6      B     
 4     7      B     
 5     4       B  

I have created two different datalists by splitting a dataset by "G". I have another datalist where G=B. This is just a subset of the two datalists . I am struggling with something that should be simple. How do I create histograms of each of these datalists together in one frame?

even a hint as to where to go next would be very helpful.....

I would say, do not split the dataset, If I merge your list I can do something like this

library(tidyverse)

datalist <- list(structure(list(O = c(3, 4, 4, 3, 2), G = c("A", "A", "A", 
                                                            "A", "A")), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"
                                                            ), row.names = c(NA, -5L), spec = structure(list(cols = list(
                                                                O = structure(list(), class = c("collector_double", "collector"
                                                                )), G = structure(list(), class = c("collector_character", 
                                                                                                    "collector"))), default = structure(list(), class = c("collector_guess", 
                                                                                                                                                          "collector")), skip = 1L), class = "col_spec")), structure(list(
                                                                                                                                                              O = c(5, 5, 6, 7, 4), G = c("B", "B", "B", "B", "B")), class = c("spec_tbl_df", 
                                                                                                                                                                                                                               "tbl_df", "tbl", "data.frame"), row.names = c(NA, -5L), spec = structure(list(
                                                                                                                                                                                                                                   cols = list(O = structure(list(), class = c("collector_double", 
                                                                                                                                                                                                                                                                               "collector")), G = structure(list(), class = c("collector_character", 
                                                                                                                                                                                                                                                                                                                              "collector"))), default = structure(list(), class = c("collector_guess", 
                                                                                                                                                                                                                                                                                                                                                                                    "collector")), skip = 1L), class = "col_spec")))
datalist %>% 
    map_dfr(~.) %>% 
    ggplot(aes(x = O, fill = G)) +
    geom_histogram(position = "dodge")
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Created on 2021-03-28 by the reprex package (v1.0.0.9002)

Thanks. The request was to have two histograms in one window so I need two separate ones.

Thank you so much. This will 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.