How to make a scatterplot in R (with regression line)

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024

Комментарии • 38

  • @alinawilke2747
    @alinawilke2747 5 лет назад +7

    Thank you! Quickly and easily explained!

  • @lilygriffiths9494
    @lilygriffiths9494 2 года назад +1

    Dude thankyou so much been stuck on this all day!! You’ve helped massively!!

  • @sonam502
    @sonam502 2 года назад

    thank you! very simple, straight to the point and very organized

  • @SerafinKeilin
    @SerafinKeilin 5 лет назад +1

    You explained that easy and short and I understood it and it really helped right away, thanks alot!

  • @Thatonepersonwholikesmath
    @Thatonepersonwholikesmath 5 лет назад +18

    Great video, but I am trying to do just this, had the same code you used. R didnt return any errors, but my regression line does not show up on my scatterplot. Any help on why that is would be appreciated.

    • @thatrnerd4265
      @thatrnerd4265  4 года назад +8

      Sorry this is 3 months past the question, it looks like a lot of people are having this issue based on the number of thumbs on this post. If you, or anyone who is having this issue could post their code I could take a closer look. I know it's only two lines, but it only takes something small for it not to work. Without seeing the code, I would guess that the variables need to be switched on abline. So where we have plot(x-variable, y-variable) we need abline(lm(y-variable ~ x-variable, data = data))

    • @arjanlail1288
      @arjanlail1288 4 года назад +13

      For people looking at this in the future, the most common mistake is in the abline. Here it's abline(lm(mpg ~ hp)...... try switching the mpg and hp around in that part of your code. So for example, if you have plot(X,Y), then it would look like abline(lm(Y ~ X, .........

  • @surachetn2563
    @surachetn2563 6 лет назад +1

    thanks. your video helps me a lot.

  • @carlys8439
    @carlys8439 6 лет назад +10

    The abline doesnt work for me

  • @lilia.2869
    @lilia.2869 5 лет назад

    Thanks for the help! Very easy to follow

  • @AsirAjmal
    @AsirAjmal 5 лет назад

    Please make more videos on R. I am a psychologist who likes your simple and easy method of teaching stats with R. Please also cover non linear models, ancova, manova, repeated measures etc in your future videos. But using the same easy method. Great stuff.

    • @thatrnerd4265
      @thatrnerd4265  5 лет назад +1

      Thank you for the feedback! I do have one video on ANOVA if you want to check it out here... ruclips.net/video/qrP7evoNCy4/видео.html
      The rest are great ideas for future videos for me to work on!

    • @AsirAjmal
      @AsirAjmal 5 лет назад

      @@thatrnerd4265
      Thank you so much for the link and for listening to my suggestions. Cheers.

  • @remonhany
    @remonhany 4 года назад

    That was really helpful, THANK YOU!

  • @knowledgeahadzitse6628
    @knowledgeahadzitse6628 3 года назад +1

    Please I am working with several subsets of data, can I get an explanation on what to do. The question goes like this, for birth weights and pregnancy, I should assign women who smoke to 1, those who don't to 2, and those who never tried to 3. Them I should later plot a graph of the birth weight in addition to the pregnancy of those who didn't, thus 2.

  • @apsietese8718
    @apsietese8718 3 года назад

    Thank you very much

  • @vabiyanasafira1671
    @vabiyanasafira1671 6 лет назад

    this is really helpful, thanks!!

  • @bxatch
    @bxatch 4 года назад +1

    Thank you!

  • @vincentray1883
    @vincentray1883 4 года назад

    Awesome vid, so much out of so little

  • @emilygalen3371
    @emilygalen3371 5 лет назад

    Is your third variable on your 'Enhanced Scatter Plot' a control or an instrument? Thanks for the video!

  • @daughterofunicorns3873
    @daughterofunicorns3873 2 года назад

    Hey! Thank you very much for your useful video. I was just wonderin though: somehow I have made it such that my plots appear in a new window (i.e not in the console). Every plot I do, it makes a new window that minimises when I change my code. How do I change it bac so that my plots appear only in the plot section of the console?

  • @madhusankawijerathne8435
    @madhusankawijerathne8435 Год назад

    Thx sir

  • @21Arrozito
    @21Arrozito 5 лет назад

    is it necessary to specify the data source in the abline function? I tried with specifying it and without it and the same regression line still plots the same either way.

  • @ciaomalli993
    @ciaomalli993 2 года назад

    thank you

  • @AsirAjmal
    @AsirAjmal 5 лет назад

    Wow. This is awesome.

  • @tamerajames5590
    @tamerajames5590 3 года назад

    My scatter plots don’t look right, what am I doing wrong? Please help because my assignment is due Tuesday!

  • @CB_2023
    @CB_2023 3 года назад +1

    I keep getting these errors when I plot 2 independent ad one dependent variable. How do I fix it???
    ## Warning in scatterplot.default(X[, 2], X[, 1], groups = X[, 3], xlab = xlab, : number of groups exceeds number of available colors
    ## colors are recycled

  • @volatility777
    @volatility777 5 лет назад +3

    I am a complete beginner in programming. Can someone tell me the proper way to enter ~ within the lm() function please? I have tried shift # but didn't work. Thanks

    • @thatrnerd4265
      @thatrnerd4265  5 лет назад +1

      Press shift and then the button to the left of 1.

  • @vincenzo4259
    @vincenzo4259 2 года назад

    Thanks

  • @oc_pr2087
    @oc_pr2087 2 года назад

    I cant find the package car when you did library(cars)

  • @antoniomanco6728
    @antoniomanco6728 6 лет назад

    Hi.
    Thank you for this video.
    I have one question:
    How can I get the R -squared value or other information about regression, for each regression line recognized trough a third variable with "car-scatterplot"?
    If I use summary(lm(y~x,data=mydata)) I have information about the whole selected dataset and not about each subgroup recognized trough "car-scatterplot" and a third variable.
    I hope the question is clear.
    Sorry, but I'm newbie of R.

    • @thatrnerd4265
      @thatrnerd4265  6 лет назад +1

      I would use the ggplot2 package and ggpmisc package to get that information. For this dataset, this should do it ...
      (If packages are not installed you must install them)
      library(ggpmisc)
      library(ggplot2)
      library(datasets)
      ggplot(mtcars, aes(x = hp, y = mpg, col = factor(cyl))) +
      geom_point() +
      geom_smooth(method = 'lm') +
      stat_poly_eq(formula = y ~ x, aes(label = paste(..eq.label.., ..rr.label.., sep = "~~~")), parse = TRUE)
      So what this code does is says we are using ggplot on the mtcars dataset, x is horse power, y is mpg, and the colors for our graph are going to be based on cyl (which we have to make a factor since right now it is numeric).
      Then we plot the points on the graph.
      Put a linear regression line through the three sets of points with confidence bands around them.
      Plot the linear equation for three separate lines as well as their R^2 values.
      Hopefully this is of help to you!

    • @antoniomanco6728
      @antoniomanco6728 6 лет назад +1

      Thank you very much for the help.
      I will try it, immediately!

  • @rocketboyjv5474
    @rocketboyjv5474 Год назад

    displacement wtf?!?!?!