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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
fgmh
Frequent Visitor

Make legend colours consistent while using slicer (R Visuals)

Hello,

 

I have created my own R visuals using ggplot2, which automatically chooses a colour scheme for my legend. However, when I use the slicer to filter the data, the colours are reassigned, making it visually a bit disorienting to the user.

 

For example, before using the slicer:

A - Red

B - Green

C - Blue

D - Orange

 

After using the slicer to select C and 😧

C - Red

B - Green

 

Is there a way to make it such that after selecting C and D in the slicer, this is what I get:

C - Blue

D - Orange

 

Thank you!

2 REPLIES 2
v-chuncz-msft
Community Support
Community Support

@fgmh,

 

Based on my test, you may use scale_manual.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello Sam,

 

Thank you for your suggestion! I realise that I was not very clear in my question, sorry about that!

 

I am trying to create a Power BI template that is as generic as possible - the number of legend entries and the names of the legend entries will change each time, so I cannot hard code something like:

 

dd.col <- c("#FF0000FF", "#FF8B00FF", "#E8FF00FF", "#5DFF00FF")
names(dd.col) <- c("A", "B", "C', "D")

 

and call "scale_fill_manual("Legend", values = dd.col)"

in ggplot

 

I have tried to create a new colour palette,

 

# Create color vector
dd.col <- rainbow(length(unique(dataset$LegendEntries)))
names(dd.col)  <- unique(dataset$LegendEntries)

 

Like this, but the colours reset when I choose a subset of information using the Slicer in Power BI.

 

Would you know of a way to work around this? Thank you!

 

Regards,

Fel

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors