Barplot using R with error bar, Data Visualization, GGplot2, Plotting data ranking

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 มิ.ย. 2020
  • #barplot #R #datavisualisation #Rprogramming #datavisualisation #ggplot #datanalysis #barplot
    This video discuss the visualization of data to study the ranking of variables. This plot compares different groups in variables and visualizes those bars of heights corresponding to the stat used. In this video how to control colors of bars, how to get stacked, and grouped bar plots are discussed. The data manipulation to prepare the data to plot bar plot and error bars has also been discussed.
    ggplot, geom_bar, bar plot, bar plots in R, how to make bar plot in R, how to create stacked bar chart, stacked bar in R, ggplot2 bar charts, histogram chart...
    Script file used in this tutorial
    drive.google.com/file/d/1L-Zm...
    To use the above link you have to change the working directory and set it to your own working directory using setwd() function.
    data files used
    save these data files in the working directory.
    drive.google.com/file/d/16jFG...
    drive.google.com/file/d/1uRof...

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

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

    Best video about R if seen in a long time !

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

      Thanks for praising.

  • @nl7247
    @nl7247 2 ปีที่แล้ว +4

    Very helpful explanation about sorting the data and formatting the data frame, and the graph details, every part is very helpful. Thank you.

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

    You have saved me a lot of time and effort! Thank you.

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

      Thanks for good words. Do watch my videos.

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

    Thank you so much for the clear explanations!

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

      Thanks for appreciation. Please watch my other videos also and subscribe to my channel. Share these with your friends.

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

    Thankyou so much Sir, it really helped me to organise my data and plot and you have explained it so clearly.

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

    Very informative!

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

    Hello from Greece man and thank you for saving me so much time ! It worked perfect !

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

      Thanks for the appreciation.

  • @AlexGonzalez-je8gm
    @AlexGonzalez-je8gm 2 ปีที่แล้ว +2

    This is the most informative, thorough, and helpful video I have come across. thank you for your work and for the upload it has helped me a lot

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

      Thanks, it helped . Do watch my other videos and share with your friends also.

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

    Thank you so much I was loosing so much time trying to do this on my own! This video was so much help!

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

      thanks.please subscribe and share with your friends.

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

    Explicitly explained. Glad I found your channel

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

      Thanks for appreciation. do Watch my videos and support my channel by sharing in your contacts.

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

    Thank you so much!

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

    Thank you so much. This video is very informative and easy to grasp.

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

      Please recommend this to your friends watch my other videos also.

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

    Awesome video! Thanks!

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

    Thank you! Helped a lot!

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

      Glad, it helped you. Please watch my other videos also and suggest improvements.

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

    thank you very very much!!!

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

    Thank you, very interesting session, it helped me to get what I was asking for.

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

      Glad it helped you. Do watch my other videos also.

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

    Thank you very much!!! this is an amazing video!! really helpful!! Please, do more videos. Thanks again!!

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

      Thanks for appreciation. Please share with your friends. And subscribe if you have not subscribed yet.

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

    that's comprehensive presentation, thanks a lot

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

      Thanks a lot for appreciation.

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

    Thanks for the knowledge transferring 💚

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

    This has been very helpful. Thank you sir

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

      Thanks for comment. Share with your friends.

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

    Very easy and precise, thanks.

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

      Thanks for the kind words.

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

    Thanks for making this video. It was very helpful

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

      Thanks for appreciation. Do watch other videos also.

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

    thank you so much sir!

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

    thank u so much! really thanks

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

      Glad, that it helped you. Please do watch my other videos also.

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

    Thanks for the video :)

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

    Thank you sir :)

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

    Sir your teaching method is superb. Thank you. May you live long ❤️

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

      Thanks for appreciation.

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

    excellent and a great resource

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

      Thanks for kind words.

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

    Thank you!

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

    Excellent Video. You save me. Thank you so much?

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

      Thanks for appreciation. Please spread word about me.

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

    Thank you so much sir.

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

      its mt pleasure, you found it useful.

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

    Excellent!

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

    Thank you very much sir ....I really like this video ..........I prepare my graph for my master thesis , based on your this wonderful idea .....really appreciate 🙏

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

      If you require any help for data Visualisation, model fitting ask without hesitation.

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

    It is nice explanation

  • @i-Veloger
    @i-Veloger 5 หลายเดือนก่อน +1

    Amazing sir. 🤩

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

    thanks sir!

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

    Excellent Rajendra, I learned a lot!

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

      Thanks for appreciating.

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

    💯 worth.

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

    I didnt understand what you say but your video is the best

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

      Thanks for appreciation. I am trying to add subtitles. But finding it difficult.

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

    thank you very much, this video help me so much sir !

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

      Thanks for appreciation. This boosts my motivation to go further.

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

      @@DevResearch Sir, i have a question whether the color in "fill = Mes_type" can be changed from defult?

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

      # coloring diffrent form default
      library(tidyverse)
      df % gather(Mes_type,Length, 1:4) %>% group_by(Species,Mes_type) %>%
      summarise(Mean_length=mean(Length), sd_length= sd(Length))
      plot= ggplot(df,aes(Species,Mean_length,fill=Mes_type))+
      geom_bar(stat="identity",position="dodge")+
      geom_errorbar(aes(ymin=Mean_length-sd_length,ymax=Mean_length+sd_length), position=position_dodge(width=0.9),width=0.2)+
      theme_bw()

      # change color using scale_fill_manual function.
      #Here number of colors must be equal to the numbers of groups to be colored.
      # you can pick the colors by searching html color picker from google search
      plot + scale_fill_manual(values = c("#00AFBB", "#E7B800", "#FC4E07","#58D68D"))

      ##predefined ggplot2 colorpalettes
      library(viridis)
      plot + scale_color_viridis(option = "D")
      plot + scale_color_viridis(option = "E")
      # package ggsci has scientitifc journal color package
      library(ggsci)
      plot+scale_fill_npg() # nature publishing group color pallette
      plot+scale_fill_lancet() # Lancet color pallette
      # Rcolorbrewer package contains many color palettes, scale_fill_brewer() for box plot, bar plot, violin plot, dot plot, etc and scale_color_brewer() for lines and points
      library(RColorBrewer)
      plot+scale_fill_brewer("Dark2")
      plot+scale_fill_brewer("Dark3")
      # ggplot gray palletes
      plot+scale_fill_grey(start = 0.8, end = 0.2)
      #This is suffieicnet ofr your purpose. Or you can visit: www.datanovia.com/en/blog/ggplot-colors-best-tricks-you-will-love/#:~:text=Change%20ggplot%20colors%20by%20assigning,or%20to%20the%20fill%20arguments.

  • @Ashishchauhan-ri8no
    @Ashishchauhan-ri8no 3 ปีที่แล้ว

    you are awesome. dude

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

      Thanks for good words. Please do watch the videos I make.

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

    great video, thanks. can you tell how i can change the colors of the bars, because i do not like the colors teh appear first so much. and also: is there a way to arrange the bars (e.g. sepal width-sepal length-...? cheers

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

      Very soon will make a video to demonstrate customizing colors. And then will go to arrange bars as we want them to be

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

    very helpful! I have followed you with my data exactly the same type but from line 98, codes are running and no error show up, but bar plots are not printed in R Markdown.

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

      You can share your code and data with me on rajuchoure@gmail.com. i will work on the code to find out the issue.

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

    Hey, thanks a mil for this. I'm having some trouble when doing this on my own dataframe.. when I calculate mean and sd, it just returns NAs and . I can get means when I use summarise_at(c("length"), mean, na.rm = TRUE) but no luck with creating SDs or SEs columns. Any advice?

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

      Need to see the data. It happened with me some times, but I forgot the context. Can figure out with your dat.

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

      @@DevResearch Thank you. I will send an email :)

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

      I updated all my packages and it worked!! thank you and apologies, I should have checked
      🤦‍♀️

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

    Thank you for this great video! Can you tell me what is the difference between line 66 and 70 of the code? I see they both return the same result,?

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

      line 66 is
      df_sumzd=group_by(df_long,Species)
      here just grouping is done. This i used to demonstrate the grouping only. Result gets saved as object df_sumzd
      On line 70
      df_sumzd=group_by(df_long,Species,Mes_type) %>% summarise(mean=mean(length),sd=sd(length))
      i Hve added the code for summarizing , and again the result gets saved as df_sumz. here the output of line 66 gets replaced by output of line 70.
      And now df_sumz will show you the output of line 70 only and not of line 66. If you clean up the environment and run the code form line 26 again you will get grouping results for line 66, which will get replaced by output of line 70, when you run the line 70.
      group_by() function groups the numeric output by the combination of categorical grouping variables.

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

    Thanks for the explanation. I have a question. How to add the error bar for #colors- stacked bar plot section. We need that sometimes. Thx

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

      Will try that and share code here.

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

    Here Rajendra Choure used Readily available SD values. In fact, we can also calculate, Mean, SD or SE from variables observations.

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

      Yes, those are actually calculated using summarise function of Dplyr. This function applies any other function to all categories in the variable.

  • @md.mahamudulhasanmredul9433
    @md.mahamudulhasanmredul9433 2 ปีที่แล้ว

    Very nice vedio, and informative. Do you know how to add ANOVA or significance value in a group boxplot!!

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

    Very nice! Could you show how to change the font of the names (setosa , versicolor, virginica) to italic? Thank you for your attention!

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

    Can we cut down the high value of bar plot to look good with low value in ggplot2 as in origin

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

      Sincere apologies for replying late. This shall not be done to bar plot as the minor differences will be exaggerated. But still if you need to do this then a great lot of coding is required to trick geom bar to limit the axis.

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

    This is really helpful. Thank you a lot. Please my concern is how can you visualized one categorical variable (qualitative variable with two or three modalities) and three or two numerical (quantitative variables) in a barplot with r using ggplot. I am really confuse about how to represent it. Thank you again.

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

      Can you share few rows of data, so that i can understand requirement and think of solution.

  • @yenealemalemneh8957
    @yenealemalemneh8957 13 วันที่ผ่านมา

    how can added the specific value of LSD value by numeric below the graph

    • @DevResearch
      @DevResearch  13 วันที่ผ่านมา

      # Sample data
      df

    • @yenealemalemneh8957
      @yenealemalemneh8957 12 วันที่ผ่านมา

      @@DevResearch library(AgroR)
      data(pl)
      with(pl,FAT2DIC(Org,Inorg,Crop_growth_rate,ylab= "Crop_growth_rate(cm)", xlab = "Org(L/ha)",
      addmean= FALSE,mcomp = "lsd",textsize= 12, width.column = 0.9,width.bar = 0.3, legend= "Inorg(%)",))
      I am use these syntax but I get only the specific value of CV and P-value, but not LSD below the graph, can you help me?

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

    Hello sir, Can you tell if we have very big dataset but on barplot we want to show top 5, How will do that ?

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

      you need to order the data , you can use arrange() fucntion of dplyr, then subset the data to filter out top five observations or groups as you require and then go for barplot.

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

    I have a problem converting an Excel sheet in a *.csv file. I've searched all day for solutions, but nothing seems to work. After I select the sheet and save it as "CSV(Comma delimited)", pressing OK and Yes as Excel tells me there could be some problems, the file opens in format .csv without putting all the date in one column separated by commas... it just remains the same and obviously I get an error when I try to open it with R.
    Is there someone who had the same problem? Did you find the solution? I even uninstalled and reinstalled Microsoft Office 2016 or cancelled the last two columns because they contain commas. Nothing works...
    I would really appreciate if you could help me.
    Thank you!

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

      If possible send me the Excel file and the r code which you are using by mail to rajuchoure@gmail.com. After converting excel to csv don't open the file in excel. right click the file and use open with option. Open the file with notepad. You will see comma separated values.
      I save he file in the same folder where i store my R file. I set that folder as the working directory, and use read.csv("filename.csv") to import the csv file in R . I store it in a data frame.

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

    I have a question here plz, i want to arrange the barplots, I want to put virginica, than setosa and versicolor in this order how to do it ?? thank you very much

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

      library(dplyr)
      library(ggplot2)
      library(tidyr)
      library(forcats)
      #Method1:
      #you can change order of level of factor by redeclaring it. for example
      iris$Species= factor(iris$Species,levels=c("virginica","setosa","versicolor")) and then go for plot.
      iris$Species = factor(iris$Species,levels=c("virginica","setosa","versicolor"))
      plot % gather(FlowerOrgan,Length,1:4) %>%
      group_by(FlowerOrgan,Species)%>%
      summarise(mean_Length=mean(Length),sd_Length=sd(Length)) %>%
      ggplot(aes(Species,mean_Length,fill=FlowerOrgan))+
      geom_bar(stat="identity",position="dodge")+
      geom_errorbar(aes(ymin=mean_Length-sd_Length,ymax=mean_Length+sd_Length),width=.2,
      position=position_dodge(.9))
      plot
      #Method 2
      #you can use forcats library function fct_relevel in mutate function of dplyr to reorder factor.
      df % gather(FlowerOrgan,Length,1:4) %>%
      group_by(FlowerOrgan,Species)%>%
      summarise(mean_Length=mean(Length),sd_Length=sd(Length)) %>% mutate(Species = fct_relevel(Species,
      "virginica", "setosa", "versicolor")) %>%
      ggplot(aes(Species,mean_Length,fill=FlowerOrgan))+
      geom_bar(stat="identity",position="dodge")+
      geom_errorbar(aes(ymin=mean_Length-sd_Length,ymax=mean_Length+sd_Length),width=.2,
      position=position_dodge(.9))

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

      You can reorder the factor levels before plotting. For example iris$Species= factor(iris$Species,levels=c("Virginica","setosa","versicolor"))
      And then go for plot.

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

      @@DevResearch I use the command below, some bars were empty, i had this error Warning message:
      Removed 18 rows containing missing values (geom_bar).
      were is the mistake , thank you .
      df_sumzd=group_by(df_long,pathway,Samples) %>% summarise(mean=mean(length),sd=sd(length))
      p=ggplot(df_sumzd,aes(x=pathway,y=mean,fill=Samples))+
      geom_bar(stat="identity",position="dodge") +
      geom_errorbar(aes(ymin=mean-sd,ymax=mean+sd),width=0.25,
      size=1,position= position_dodge(0.9),alpha=0.3)+
      theme(axis.text.x = element_text(angle = 45, hjust = 1))+
      scale_x_discrete(limits=c("Nitrogen","Methane","Carbon","sulfate","Thiosulfate","nitrification","nitrate"))
      p

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

      Please see the df_sumz. You may have missing values in the mean column. For some of the pathways or samples , there may not be any data. If possible mail me your send me df_long in CSV format or df_sumz in CSV format, so that I can try the code and find out the exact error and if any missing data is there, I can suggest imputation.

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

      @@DevResearch both files are correct , noo missing value. can I have you email pls. Thank you very much

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

    Hello can we plot image on x axis ?

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

      I will have to try, do you want image with axis title

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

      We want both name of country with flag for stacked bar chart

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

    my label doesn't show on bar, why please tell

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

    Please share with us a video about 3 way factorial anova and plotting having alphabet lettering or.if you already have video please share with me
    Thanks dear

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

      I shared the video. Please visit my TH-cam channel.

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

    Cannot thank you enough haha

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

      Watch my other videos also. This Are also good.

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

    I can't see in the movie. The qualification of the movie is too bad

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

    Is this English? I now think Nigeria has better command of english. LOL!

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

      Yes. Nigerians speak better English. But still I find it difficult as i don't have practice of listening to Nigerian accent. But in recent future , i will learn that from my Nigerian students.