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

Поделиться
HTML-код
  • Опубликовано: 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
    RUclips 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

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

    well explained.
    always perfect.

  • @RUJedi
    @RUJedi Год назад +1

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

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

      Tidyverse extends functionality.

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

    Thank you so much

  • @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.

  • @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