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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
rsbin
Community Champion
Community Champion

Help with R Script - Reverse Colour Gradient

Good Afternoon,

First time using the R Script Visual.  Almost got it to where I need it, except for one hiccup.

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset <- data.frame(WFD, VisitCount, AvgTIY)
# dataset <- unique(dataset)

# Paste or type your script code here:
library(ggplot2)
ggplot(data=dataset, aes(x=VisitCount, 
                         y=WFD)) + 
   geom_point(aes(colour=AvgTIY), size=7) +
   scale_fill_brewer(palette = "Blues")

This code gives me this visual:

rsbin_0-1646858594414.png

I would like to reverse the colour gradient so Light is low and Dark is high. 

Any help from R users is much appreciated.

Thanks and Best Regards,

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @rsbin 

 

You can use a reverse scale, but this will also flip the legend to start at the top:

Example:

ggplot(faithfuld, aes(waiting, eruptions)) +
    geom_raster(aes(fill = density)) +
    scale_fill_continuous(trans = 'reverse')

 

Here is the related document, hope it can help you.

https://stackoverflow.com/questions/43515112/reversing-default-scale-gradient-ggplot2 

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

rsbin
Community Champion
Community Champion

@v-zhangti,

Appreciate the reply.  I have seen this question on stackoverflow and it did not help me.  I am working with points and have tried numerous combinations of code.  Hence eventually posted here in hopes of getting an answer that applies to my scenario directly.

Do appreciate you taking the time to reply, but am still in need of help and/or further direction.

Thanks and Kind Regards,

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.