Stacked Barplot in R, A stacked bar chart is a type of bar chart that looks at two categorical variables instead of just one when examining numerical data.

A stacked barplot is a type of chart used to display the composition of a whole or total value in terms of its parts.

It is created by stacking individual bars on top of each other, with each bar representing a specific category or component of the whole.

The height of each bar represents the proportion or percentage of the total value that it contributes.

Stacked barplots are commonly used in data analysis and visualization to compare the relative sizes and contributions of different categories or components to a larger whole.

## Stacked Barplot in R

This article explains how to make one with R. Here, a stacked bar chart is produced using the barplot() method.

Predictive Modeling and Data Science » Data Science Tutorials

barplot(H,xlab,ylab,main, names.arg,col) is the syntax.

Setting parameters

H: is a bar chart vector or matrix that holds numerical values. xlab: The label for the x-axis. ylab: The label for the y-axis. main: The bar chart's title. names.arg: A vector of names that show beneath each bar. col: is used to give the graph's bars colors.

dat <- read.table(text = "A B C D E F G 1 20 80 30 90 70 60 90 2 30 50 70 50 40 10 40 3 50 80 80 60 60 30 160 4 10 40 70 80 20 10 70", header = TRUE) barplot(as.matrix(dat))

dat <- read.table(text ="A B C D 1 1010 500 650 708 2 1200 500 800 655", header= TRUE) barplot(as.matrix(dat),col=c("black","red"))