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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
beaverbuzz85
Regular Visitor

Problem Creating Box plot with R (wrong mean and median)

Good morning!

 

I am encountering some issues while trying to create a box plot with R. 

The plot loads on the screen, i..e no problems with libraries; however, the mean and median are completely wrong.

 

beaverbuzz85_0-1685547944104.png

beaverbuzz85_0-1685549296238.png

 

For the far left box, the mean is supposed to be 4.3, yet, as you can see it is closer to 50.

 

I believe the problem lies with R determining how to calculate mean and median with the raw data. Although, it appears the dots on the box plot are correct, i.e. they correspond with the numbers in the raw data.

For clarity, the raw data contains about 200,000 rows and each row contains a number (IND_CASE_COUNT) and a category (PCTY_CD). 

 

Any help on this would be appreciated. I ran into a similar problem with one of the downloadable visuals, as it produced a box plot but it was not producing the correct mean and median. 


Thank you 🙂

 

2 REPLIES 2
beaverbuzz85
Regular Visitor

I am not sure if we are allowed to bump messages. I would appreciate some help, even if it means posting this in a different forum. Thanks!

FYI boxplots do not display means! The lines in the boxplots you posted are the medians of each group and each box stretches between the 1st and 3rd quartiles of your data. So, first thing I'd suggest is checking if some medians you calculate in your data are matching up with the boxplots. If you're finding the box plots are still not lining up with your expectations, the only Power BI element I could see contributing to the issue is if you're summarizing the fields you added to the visual or something. You could also just build the plot in R (outside of PBI) and see if they are the same to confirm whether PBI is affecting the output.

 

Hope this helps!

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.