Forum Discussion

asayat's avatar
asayat
Regular Visitor
9 years ago

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

 

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.

3 Replies

  • v-huizhn-msft's avatar
    v-huizhn-msft
    Microsoft 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.



    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


     

    • asayat's avatar
      asayat
      Regular Visitor

      Dear Angeliav-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.

       

      • v-huizhn-msft's avatar
        v-huizhn-msft
        Microsoft Employee

        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