Home > Software design >  How to make R side by side two column histogram (see images)
How to make R side by side two column histogram (see images)

Time:03-22

This is what I wantHow to make R side by side two column histogram (above) which I am able to do in python (enter image description here

CodePudding user response:

Here is an example using the iris data set. First you have to bring the data in long format with pivot_longer

and then apply geom_histogram() with position= 'dodge'

library(tidyverse)

iris %>% 
  pivot_longer(
    c(Sepal.Length, Sepal.Width, Petal.Length)
  ) %>% 
  ggplot(aes(value, fill=name)) 
  geom_histogram(position = "dodge")

enter image description here

  • Related