Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
I want to show stacked bar chart that colors values' category but does not aggregate the data.
The dataset in use:
STR | Order | Cat | Id | Size |
bird | 1 | a | 50002 | 1 |
bird | 2 | b | 50006 | 1 |
cat | 1 | a | 50001 | 1 |
cat | 2 | b | 50004 | 1 |
cat | 3 | b | 50005 | 1 |
cat | 4 | b | 50009 | 1 |
dog | 1 | b | 50003 | 1 |
dog | 2 | a | 50007 | 1 |
dog | 3 | a | 50008 | 1 |
I need to show each Size value in each STR colorized by Cat and order by Order.
Here's my attempt using legend - cat
I want the final result be something like this:
The last graph was generated via Rscript:
library(ggplot2) library(data.table) library(plotly) db<-data.table(dataset) setorder(db, Order) ggplot(db, aes(x=STR,label=Order, y=Size) )+ geom_bar(aes(fill=Cat),stat="identity", color="blue")+coord_flip()+ guides( color=FALSE)+ geom_text(size = 3, position = position_stack(vjust = 0.5))
The main problem is that R graphs are not interactive, so need to use powerBI visual option.
Hi @asayat,
You can create R visual in Power BI desktop.
First, you need to get data, create a resource table, please see the following screenshot.
Second, select the R visual, select all the column as dataset. Type your R script and run it, you will get expexted result.
Please feel free to ask if you have any other problem.
Best Regards,
Angelia
Dear Angelia@v-huizhn-msft, thank you for your response!
The problem with R visual is that it's not interactive with other visuals. There is a need to have a plot as described above and click to any bar and get more specific information for that cell in other tabular visual. It can't be done by simply R visual.
Hi @asayat,
I understand your requirement now, while there is no such visual in Power BI desktop. After research, I find a custom visual (Table Sort), which is same with what you want but closer to. Please see the following screenshot. For same STR, cat a and b are shown in different colors.
Thanks,
Angelia
User | Count |
---|---|
139 | |
113 | |
103 | |
73 | |
63 |
User | Count |
---|---|
136 | |
125 | |
107 | |
70 | |
61 |