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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
PVS07
Helper III
Helper III

R visual sort order

Hi All,

Not sure if this is the right place to request as this is about a R visual. However, as the visual is part of the Power BI report I thought I might give it a try. Let me know if this is not the right forum.

 

I have developed a Power BI report with custom sort of geographic hierarchies. There are 4 levels and I have created the right sort order in the data tables. Using this sort order I have built 2 visuals, a Matrix table and an R bar chart. I used the R chart as I needed error bars and it is not available in other visuals. I am very new to R, searched the internet and I was able to build the bar chart with error bars.

My issue is the matrix table is working with the custom sort that I have built and is in the right order. However the R visual is in alphabetical order. I have searched the internet and was able to find code that will allow manual sorting of the items but this will work only if it is static. My chart is meant to be dynamic and the geography items change when I apply the filter. 

 

Is it possible to get the R visual to follow the custom sort order that I have built. If you can help me that will be greatly appreciated. 

 

Please see the screenshot below for more detail and here is my R code for your reference/review

 

Thank you.

 

library(ggplot2)
ggplot(unique(dataset), aes(x = LGA, y = Rate)) +
geom_point(size = 5, stroke = 0, shape = 18, colour="brown") +
geom_point() + geom_line() +
geom_errorbar(aes(ymin = LL, ymax = UL), width=0, position=position_dodge(.9), colour="brown", alpha=0.3, size=4) +
# remove background
theme_bw()+
# remove grid
theme(panel.grid.major = element_blank()) +
# axis labels placed at a 45* angle:
theme(axis.text.x = element_text(angle=45, hjust = 1))+
# x axis text size
theme(axis.text.x = element_text(size = 10))
 
R sort.png

 

6 REPLIES 6
v-diye-msft
Community Support
Community Support

Hi @PVS07 

 

If the above posts help, please kindly mark it as a answer to help others find it more quickly. thanks!

If not, please kindly elaborate more.

 

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.
amitchandak
Super User
Super User

@PVS07 , I think you need to make visual sure visual is sorted by R

Hi @amitchandak - Thanks for the answer. However, when I clicked on the ellipse  button there was no sort option available like you get in other visuals.  Please see the screenshot below

 

Sorry if I interpreted your answer incorrectly.  

 

PVS07_0-1599111749570.png

 

@PVS07 , if the visual is created in R. then return a sorted visual 

lbendlin
Super User
Super User

https://www.r-graph-gallery.com/267-reorder-a-variable-in-ggplot2.html

 

By the way, you don't need unique() - Power BI already does that for your dataframe as mentioned in the comments of the R visual.

Hi @lbendlin  - Thanks for the link and the quick tip on unique(). I will check the link.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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