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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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