Customize Bar plot in R -GGplot2- in 5 steps : Beautiful publication ready bar plot

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ก.ค. 2024
  • #barplot #errorbars #ggplot2 #Rprogramming
    #R #datavisualisation #Rprogramming #ggplot #datanalysis #barplotcustomisation
    This video discuss customisation of barplot in ggplot2 R. Reordering of categories, adding error bars, plot titles, themes and color palletes have been discussed.
    library(tidyverse) # for summarizing the data to get means and sds of categories
    library(ggsci) # for color palettes of scieintifc journals
    library(ggpubr) # for theme pubr
    iris_plot = gather(iris,FlPrt,Length,1:4)
    iris_plot= group_by(iris_plot, Species,FlPrt)
    iris_plot=summarise(iris_plot,mnL=mean(Length),sdL=sd(Length))
    iris_plot= ggplot(iris_plot,aes(reorder(Species,mnL),mnL,fill=reorder(FlPrt,mnL)))+
    geom_bar(stat="identity",position="dodge")+
    geom_text(mapping=aes(label=mnL),position=position_dodge(width=0.9),
    cex=2.5,vjust=-4)+
    labs(title="Iris: Measurment of floral organs",
    subtitle="Length abd width of srpal abd petal",
    x="Species",y="Length ib cm",
    caption="Data: iris dataset by Edgar Anderson",fill="Description")+
    geom_errorbar(mapping=aes(ymin=mnL-sdL,ymax=mnL+sdL),
    width=0.2,position=position_dodge(width=0.9))+
    theme_classic()+scale_fill_jco()
    0:00 Introduction
    0:49 Install and load required packages
    1:34 Prepare data
    2:34 initiate ggplot
    3:36 Reorder categories of bars
    4:56 Add value labels to bars
    6:02 titles of plot elements
    7:05 Add error bars
    8:39 add theme to plot
    10:16 Add color palettes
    11:20 concluding remarks

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

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

    Really easy to digest. Thank you so much

  • @user-xd6cl3fe5w
    @user-xd6cl3fe5w 7 หลายเดือนก่อน

    Thank you, sir, for steering me in the right direction with many of these topics. Your videos are clear and have been very helpful. Thank you so much.

    • @DevResearch
      @DevResearch  7 หลายเดือนก่อน

      Glad you liked it. Thanks. Please keep watching my channel and recommend it to others.

  • @sarahasadraza
    @sarahasadraza 2 หลายเดือนก่อน

    struggled for a long time trying to make my bar plots, this helped me a lot ! subscribed !

    • @DevResearch
      @DevResearch  2 หลายเดือนก่อน +1

      Glad that it helped. Do watch my other videos.

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

    Thanks a lot, very informative tutorial. This Really helps!

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

      Thanks for appreciation. Do share with your friends.

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

    Thank you for your informative video!

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

      Glad it was helpful!

  • @garethomarrostroalonso9026
    @garethomarrostroalonso9026 11 หลายเดือนก่อน

    Thanks to you sir. I will have a beautiful bar plots! Regards from México

    • @DevResearch
      @DevResearch  11 หลายเดือนก่อน

      So nice of you. These comments make my day.

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

    explained really well !! Thank you sir

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

      Thanks for appreciation

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

    Thanks a lot! It really helps me!

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

      Thanks for good words.

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

    Elegant presentation

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

      Thanks very much. Please watchy other videos also.

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

    Thank you, Sir

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

    Very helpful!!!

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

      Thanks for good words. Keep watching my videos

  • @sama-hf3yv
    @sama-hf3yv ปีที่แล้ว +1

    Thank you

  • @OR-nh4ss
    @OR-nh4ss 2 ปีที่แล้ว

    Thanku! u saved my day!

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

      Thanks a lot for appreciation.

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

    Respected Sir, I want to let you know that how much I am thankful for your videos and really appreciate your efforts for teaching us. Thank you so much sir. May god bless you with good health and success !

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

      Thanks for appreciation. This will motivate me to work more.

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

      @@DevResearch Sir, I am having a problem. The error bars are generated slightly inside the bars and not at the edge. How can I fix this? And, also I am not able to reorder the bars, its not working for me. I'm using your shortcut method for bar graphs.

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

      Share your code to rajuchoure@gmail.com, with data. I will look at the code and will correct it

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

    👍😊

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

    Dear Sir, your tutorial helped me lot within 11 minutes. I am a very beginner in r studio, just shifted from excel to R for preparing graphs. It will be nice if you make a video or any recommendation regarding my two problems. 1. I want to show the plant height increment within 6 months time period at different treatment groups. It will be a group bar plot. How will I create a group bar plot of my own data like customized data that you showed in the tutorial? 2. which theme provides the barplot that has separated x-axis and y-axis , not joint like the theme_classic() ? Thanks

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

    If i do not use stat identity here, how can I add count on the bar plot by using geom text? could you please explain it?

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

      you can use stat="bin" to get counts. you need to convert the variable of which counts are being plotted to factor. Like this. Then in geom text use stat= "count" and label = ..count.. in aes.
      # Don't map a variable to y
      ggplot(mtcars, aes(x=factor(cyl)))+
      geom_bar(stat="count", width=0.7, fill="steelblue")+
      theme_minimal()+
      geom_text(stat='count', aes(label=..count..), vjust=-1)

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

    I tried this. But my groups are of different lengths, and the bars of different groups are of different widths. Is there a way to fix that?

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

      I am not able to imagine the data. If possible, send me data, I will try and share code with you.

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

    Professor, can you demonstrate how to perform a “distance based Redundancy data analysis (db RDA)” in R ?

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

      Will try.

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

      Yes, Professor. Please help us providing a video related to db RDA. It’s really worthy in my case. Thank you!

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

    Sir please help me .... after clicking geom_text coding portion it is showing -
    Error in 'fortify()':
    'data' must be a , or an object coercible by 'fortify()' not an s3 object with class /.

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

      Share few rows of your data and your script. I will try the plot.

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

      @@DevResearch Sir I have not done anything.... used your script written above.... Still it is showing

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

      I have replicated your other bar graphs scripts those ones working properly in my device

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

    suppose you got sales data.
    you got items sold, their quantity and value
    if I were in excel I would make a bar plot for the value, i.e. sales value, and volume/quantity of items sold as line chart combined with the previous but the latter would use a secondary axis
    now, I know such a thing is possible by mapping different data to different geoms but I am facing an issue visualising the quantity on a line chart
    any ideas?
    x-axis would have categorical labels and the other numeric

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

      I will share code by tommorrow morning.

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

      @@DevResearch thank you so much for this. in excel I used to plot value in bar/column chart with a combo line chart for the number of projects per category which goes on a secondary axis

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

      # I could get this hack
      year

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

      @@DevResearch thank u for this; i will try it; possible to do it in ggplot2?

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

      thank u for this; how would you do the same idea in ggplot2 with labels for values??? I need to show the quantity of items sold and volume of sales for each product

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

    Hi, Which color pallete(theme) is suitable for color blind audience?

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

      Thanks for this question. I really didn't understood gravity of this situation.
      Package viridis claims in their introduction that
      "Use the color scales in this package to make plots that are pretty, better represent your data, easier to read by those with colorblindness, and print well in gray scale."
      cran.r-project.org/web/packages/viridis/vignettes/intro-to-viridis.html.
      Hope this solves the issue. As I currently don't have any color blind person to verify this claim.

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

    sir my x-axise is getting arrange alphabetically not according to the csv fill

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

      You have to define x variable as factor with defined levels, in the order you want those to be.

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

      @@DevResearch ggplot(Growth, aes(x = factor(Treatments, level = c('Control', 'Ni50', 'Ni100', 'BCT', 'Ni50 + BCT', 'Ni100 + BCT')), y = mean)) + geom_col()
      I'm using this code but this is giving me a error
      Error in ggplot(Growth, aes(x = factor(Treatments, level = c("Control", :
      object 'Growth.csv' not found
      could u please help me were I'm wrong

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

      Can i have to email or phone number i want want to discuss something more
      I shall be really gratefully to sir your lectures and coding helped me a lot but still there are some confusion which i want to clear

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

      @@asmodesustudi0 rajuchoure@gmail.com

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

    Hi which color pallete can I use for color blind people?

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

      scale_fill_viridis() will help here. viridsis color pallettes are for color blind friendly. And sincere apologies for replying late.