Forum Discussion
Stacked & Clustered Bar Graph using R
- 7 years ago
Hi Anonymous ,
You need to change your data frame like below:
Then, you can refer to the article to create a Stacked & Clustered Bar Graph using R.
The code is below:
>install.packages(“ggplot2”)
>library(ggplot2)
> data<-read.table(file="Budget.txt",header=T)
> ggplot(data=data, aes(x=Month, y=Value,fill=Category)) + geom_bar(stat="identity")
> data2<-with(data, data[order(Month, Category, Actual.Budget),])
> ggplot(data=data2, aes(x=Actual.Budget, y=Value,fill=Category)) + geom_bar(stat="identity")+facet_grid(~Month)
Best Regards,
Icey Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- 7 years ago
Hi Anonymous ,
In Power BI, you can write your R script like so:
library(ggplot2) data<-dataset data<-with(data,data[order(Month,Category,ActualBudget),]) ggplot(data=data, aes(x=ActualBudget, y=Value,fill=Category)) + geom_bar(stat="identity")+facet_grid(~Month)
This is my sample file.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
You can use this method as well which simulates a combined cluster and stacked chart using the built in stacked chart in Power BI.
https://www.villezekeviking.com/how-to-combine-a-clustered-and-stacked-chart-in-power-bi/