How to make and enhance barplot with data labels, error bar and legend using R programming?

แชร์
ฝัง
  • เผยแพร่เมื่อ 25 ก.ค. 2022
  • #barplot #rprogramming #datavisualization #barcharts #errorbars
    In this video I discussed how to get a complete publication ready grouped barplot using base R function.
    To get the summarize data to plot bars and std. dev for error bars , i have used summarise _all function of dplyr.
    Adjustment of margin, y axis limits and Orientation of labels to get text accommodated is also discussed.
    Facebook page:
    / rajendrachoureisc
    Mail Id:
    rajuchoure@gmail.com
    TH-cam playlist:
    • R programming tutorials
    Script
    #barplot with error bars
    #datasummary
    head(iris)
    library(dplyr)
    iris_sum_mean = group_by(iris, Species)
    iris_sum_mean = summarise_all(iris_sum_mean,mean)
    iris_sum_mean_mat = as.matrix(iris_sum_mean[,-1])
    iris_sum_sd =group_by( iris, Species)
    iris_sum_sd =summarise_all(iris_sum_sd ,sd)
    iris_sum_sd_mat =as.matrix(iris_sum_sd[,-1])
    #barplot
    par(mar=c(7,3,2,2))
    gbp = barplot(iris_sum_mean_mat,beside=TRUE,las=2, col=terrain.colors(3),ylim=c(0,7.5),main="barplot with errorbars")
    text(x=gbp, y=iris_sum_mean_mat+0.15,labels = round(iris_sum_mean_mat,2), cex=0.6)
    #Errorbars
    arrows(x0=gbp, x1=gbp,y0=iris_sum_mean_mat-iris_sum_sd_mat,y1=iris_sum_mean_mat+iris_sum_sd_mat, code=3, angle=90,length=0.05)
    #legend
    legend(x="topright", fil=terrain.colors(3),legend=iris_sum_mean$Species,bty="n")

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

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

    Your youtube channel is the best resources I came across so far for learning R. Please keep teaching us. God bless you!

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

      Thank you very much for this appreciation. It motivates a lot.

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

    Well done! Always enjoy watching base R do just as well as tidyverse options.

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

      Tidyverse extends functionality.

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

    well explained.
    always perfect.

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

    Thank you so much

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

    Thanks very much Dr. Rajendra

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

    Thanks. Hw to reorder legends such as virginica, versicolor, and setosa?

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

      Sorry for the delay in answeing, add layer - scale_fill_discrete(breaks=c("virginica", "versicolor", "setosa"))
      library(ggplot2)
      library(ggplot2)
      ggplot(data=iris, aes(x=Species, y=Sepal.Length, fill=Species)) +
      geom_boxplot() +
      scale_fill_discrete(breaks=c("virginica", "versicolor", "setosa"))

  • @dennisoce-tech1802
    @dennisoce-tech1802 ปีที่แล้ว

    Mr choure ur videos helpful my thesis writting. I need one help please upload two y axis graph with line with bar