Create a bar chart with groups of bars and stacks.

0 votes

Hi team,

I am new to data visualization in R. I want to create a stack of bars in R. How can I do that?

Oct 29 in Data Analytics by akhtar
• 33,060 points
17 views

1 answer to this question.

0 votes

Hi@akhtar,

We can create a bar chart with groups of bars and stacks in each bar by using a matrix as input values. More than two variables are represented as a matrix which is used to create the group bar chart and stacked bar chart as shown below.

colors = c("green","orange","brown")
months <- c("Mar","Apr","May","Jun","Jul")
regions <- c("East","West","North")
Values <- matrix(c(2,9,3,11,9,4,8,7,3,12,5,2,8,10,11), nrow = 3, ncol = 5, byrow = TRUE)
png(file = "barchart_stacked.png")
barplot(Values, main = "total revenue", names.arg = months, xlab = "month", ylab = "revenue", col = colors)
legend("topleft", regions, cex = 1.3, fill = colors)

answered Oct 29 by MD
• 77,980 points

Related Questions In Data Analytics

0 votes
1 answer

Changing the order of bars in a bar-plot - ggplot2 - R

You can use the scale_x_discrete() function with ...READ MORE

answered May 28, 2018 in Data Analytics by Bharani
• 4,580 points
7,502 views
0 votes
1 answer

Create a dual axis column/bar chart using ggplot in R

Add position = "stack" in geom_bar() function ...READ MORE

answered Nov 4, 2019 in Data Analytics by sindhu
799 views
+1 vote
2 answers

Custom Function to replace missing values in a vector with the mean of values

Try this. lapply(a,function(x){ifelse(is.na(x),mean(a,na.rm = TRUE ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
334 views
+1 vote
2 answers

Finding number of missing values and removing those missing values from a data-frame

To find number of missing values for ...READ MORE

answered Aug 14, 2019 in Data Analytics by anonymous
198 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,720 points
223 views
+1 vote
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
1,616 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
122 views
0 votes
1 answer

How do you have 2 different colors in a bar graph, ggplot in where one color for the negatives and positives

Hi@Andris, Once you have the data, you can make the ...READ MORE

answered Oct 5 in Data Analytics by MD
• 77,980 points
147 views
0 votes
1 answer

How to create a pie chart in R?

Hi@akhtar, In R the pie chart is created ...READ MORE

answered Oct 29 in Data Analytics by MD
• 77,980 points
15 views