Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
asayat
Regular Visitor

Legend do not aggregate values

I want to show stacked bar chart that colors values' category but does not aggregate the data.

 

The dataset in use:

STROrderCatIdSize
bird1a500021
bird2b500061
cat1a500011
cat2b500041
cat3b500051
cat4b500091
dog1b500031
dog2a500071
dog3a500081


I need to show each Size value in each STR colorized by Cat and order by Order.

Here's my attempt using legend - cat

pwoerbi.png

 

I want the final result be something like this:

rscript.png

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.

3 REPLIES 3
v-huizhn-msft
Employee
Employee

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.

1.PNG

Second, select the R visual, select all the column as dataset. Type your R script and run it, you will get expexted result.

2.PNG

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. 

1.PNG

Thanks,
Angelia

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.