Histograms in R with ggplot and geom_histogram() [R-Graph Gallery Tutorial]

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • In this tutorial I show how to create Histograms in R with hist() and geom_histogram(). The examples are based in the R-Graph Gallery. I show how histograms can be used to visualize multiple different distributions at once.
    ⏱ Time Stamps ⌚
    0:00​ - Intro and video overview
    0:58​ - hist() and cut() function for histograms
    3:18​ - geom_histogram() function arguments
    4:25​ - Mirror histogram plot
    5:12​ - Multiple histograms with position
    6:35​ - Multiple histograms with facet_wrap
    8:10 - Marginal distributions
    9:00 - Age/population pyramid
    External Links:
    www.r-graph-gallery.com/histo...
    stackoverflow.com/questions/4...
    www.trafforddatalab.io/recipe...
    Background Music:
    • PARASITE EVE 2 SOUNDTR...

ความคิดเห็น • 15

  •  2 ปีที่แล้ว +1

    Really useful. Thanks!

    • @TheDataDigest
      @TheDataDigest  2 ปีที่แล้ว

      Thanks for the nice comment!

  • @m3ick
    @m3ick 3 ปีที่แล้ว +3

    Nice tutorial. Hope you get more views :)

    • @TheDataDigest
      @TheDataDigest  3 ปีที่แล้ว

      Thank you very much, I hope so too ;)
      This is currently my 4th best performing video. Looking forward at getting better to deliver helpful content about R in the future.

  • @tajamulislamshah8494
    @tajamulislamshah8494 2 ปีที่แล้ว +1

    Kindly show how different variables can be put in one graph. Like, I have mean value of four soil properties along with 13 treatments. I wanna put these 4 soil properties along with treatments in a single graph but I don't know how?

    • @TheDataDigest
      @TheDataDigest  2 ปีที่แล้ว +1

      I can probably achieve that with the facet_wrap() or facet_grid() functions. I suggest you post your question at *stackoverflow*. Give some example data and some graphs you already created and ask there how to combine them. Usually you will get good answers there within a few days.

    • @tajamulislamshah8494
      @tajamulislamshah8494 2 ปีที่แล้ว +1

      @@TheDataDigest Thanks

  • @NatashaKasher
    @NatashaKasher 3 ปีที่แล้ว +2

    Hi, thanks for the tutorial, I personally find the background music distractive, but maybe it's just me.

    • @TheDataDigest
      @TheDataDigest  3 ปีที่แล้ว +1

      Hi Natasha, good question and thanks for your feedback. Maybe I should do the next few tutorials without music and see how well they do. If people want to listen to music in the background they can follow their own preferences anyway.

  • @jtotherock7244
    @jtotherock7244 ปีที่แล้ว

    Hello, how can I create intervals for the age like you have, 20-29. 30-39, 40-49, in the table itself? When I import a txt document I've made with the intervals in one category, they are interpreted as Character data and not double data, so I can't make histograms essentially. How have you done it?

    • @TheDataDigest
      @TheDataDigest  ปีที่แล้ว

      Hi there, thanks for asking the question. geom_histogram() or geom_density() indeed only works for continuous numeric data. In the example at 9:00 minutes I am using geom_bar() and after 10:00 I am using geom_col(). Depending on the data you can use those. Maybe you have to turn your character age-ranges into a factor with ordered levels first.
      If you still need help feel free to email me the code and the data (question[at]thedatadigest[dot]email)

    • @jtotherock7244
      @jtotherock7244 ปีที่แล้ว

      @@TheDataDigest Hi, thanks for your reply. I would need a histogram. I believe I need the range of values like you have, but for height. I need it in a table and the column name would essentially be Heights. Then I'd have the frequency for females and males. What could be your email, I may be able to show you what I have so far? Thank you

    • @TheDataDigest
      @TheDataDigest  ปีที่แล้ว

      @@jtotherock7244 I posted my mail address above. Just replace the at/dot. You can create something that looks like a histogram with geom_col() or geom_bar() by removing the space between bars. The frequency will come from counting the instances within your interval. Anyway I am sure I can help you. Feel free to include screenshots or pngs to show what the final chart should look like.

    • @jtotherock7244
      @jtotherock7244 ปีที่แล้ว

      @@TheDataDigest I see what You are saying, unfortunately I would still need a histogram. Also I cannot quite understand what the email is? I've just tried to set characters to factors but I believe It still does not work. I get an error that I need continuous x-values =(.

    • @TheDataDigest
      @TheDataDigest  ปีที่แล้ว

      @@jtotherock7244 Please send your code and some example data to:
      question@thedatadigest.email
      Sometimes online people post their mail addresses with replaced @-sigh [at] and no "." [dot]. In order not to get spam mails from bots scraping websites.