Adding a scatter of points to a boxplot (2024)

358 views (last 30 days)

Show older comments

Peyman Obeidy on 29 Apr 2018

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot

  • Link

    Direct link to this question

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot

Edited: Seth DeLand on 26 May 2022

Accepted Answer: dpb

  • boxplot_inpy.png

Does anyone come with with a code which can match the python generated boxplot?

1 Comment

Show -1 older commentsHide -1 older comments

dpb on 29 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562297

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562297

Open in MATLAB Online

Presuming the points actually a set of coordinates as shown, don't see why

hold on

scatter(x,y)

with appropriate x,y arrays and the associated color arrays, etc., wouldn't come reasonably close...

Sign in to comment.

Sign in to answer this question.

Accepted Answer

dpb on 29 Apr 2018

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_317801

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_317801

Open in MATLAB Online

Indeed, that seems to work just fine...

load carsmall MPG % the sample dataset variable

hold on

scatter(ones(size(MPG)).*(1+(rand(size(MPG))-0.5)/10),MPG,'r','filled')

yields

Adding a scatter of points to a boxplot (4)

It's possible to add color with value scaling in scatter see the details on it for all the particulars.

5 Comments

Show 3 older commentsHide 3 older comments

Peyman Obeidy on 30 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562422

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562422

Open in MATLAB Online

Here is the same thing with a bit more manipulations

load carsmall MPG % the sample dataset variable

MPG(:,2)=MPG(:,1).*2;

MPG(:,3)=MPG(:,1).*3;

boxplot(MPG,'Notch','on','Labels',{'mu = 5','mu = 6','mu = 6'},'Whisker',1)

lines = findobj(gcf, 'type', 'line', 'Tag', 'Median');

set(lines, 'Color', 'g');

% Change the boxplot color from blue to green

a = get(get(gca,'children'),'children'); % Get the handles of all the objects

%t = get(a,'tag'); % List the names of all the objects

%box1 = a(7); % The 7th object is the first box

set(a, 'Color', 'r'); % Set the color of the first box to green

hold on

x=ones(length(MPG)).*(1+(rand(length(MPG))-0.5)/5);

x1=ones(length(MPG)).*(1+(rand(length(MPG))-0.5)/10);

x2=ones(length(MPG)).*(1+(rand(length(MPG))-0.5)/15);

f1=scatter(x(:,1),MPG(:,1),'k','filled');f1.MarkerFaceAlpha = 0.4;hold on

f2=scatter(x1(:,2).*2,MPG(:,2),'k','filled');f2.MarkerFaceAlpha = f1.MarkerFaceAlpha;hold on

f3=scatter(x2(:,3).*3,MPG(:,3),'k','filled');f3.MarkerFaceAlpha = f1.MarkerFaceAlpha;hold on

Adding a scatter of points to a boxplot (6)

dpb on 30 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562430

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562430

Nice choices..looks good. :)

Peyman Obeidy on 30 Apr 2018

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562432

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_562432

Thank you

Rubina Chandnani on 22 Jul 2021

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_1650424

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_1650424

In the line of code in scatter, is there a way to use a different color using uisetcolor? (I don't want to use the default colors).

Seth DeLand on 26 May 2022

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_2180020

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_2180020

Edited: Seth DeLand on 26 May 2022

Open in MATLAB Online

I'd like to add that there is now an easier way to do this with boxchart (added in R2020a) and swarmchart (added in R2020b):

load carsmall MPG % the sample dataset variable

MPG(:,2)=MPG(:,1).*2;

MPG(:,3)=MPG(:,1).*3;

boxchart(MPG)

hold on

x = repmat(1:3,100,1); % create the x data needed to overlay the swarmchart on the boxchart

swarmchart(x,MPG,[],'red')

Adding a scatter of points to a boxplot (11)

Sign in to comment.

More Answers (2)

Hassan on 18 May 2019

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_375615

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_375615

Open in MATLAB Online

Hi, here you can find a one line solution for the jitter like function using the 'undocumented matlab' features.

load carsmall MPG

figure;

MPG(:,2)=MPG(:,1).*2;

MPG(:,3)=MPG(:,1).*3;

boxplot(MPG);

hold on;

x=repmat(1:3,length(MPG),1);

scatter(x(:),MPG(:),'filled','MarkerFaceAlpha',0.6','jitter','on','jitterAmount',0.15);

Best, HM

1 Comment

Show -1 older commentsHide -1 older comments

Junru Ruan on 13 Dec 2019

Direct link to this comment

https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_777810

  • Link

    Direct link to this comment

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#comment_777810

Open in MATLAB Online

This is the best answer! very nice presentation.

Tips: if you used group in box plot, do a 'unique' to get the right x axis.

boxplot(report_table.data,report_table.group_id);

hold on

[C, ~, ic]= unique([report_table.group_id],'stable');

scatter(ic,report_table.data,'filled','MarkerFaceAlpha',0.6','jitter','on','jitterAmount',0.15);

xlabel('Group ID');

ylabel('Data');

hold off

Sign in to comment.

Ernesto Salcedo on 27 Nov 2020

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_557928

  • Link

    Direct link to this answer

    https://support.mathworks.com/matlabcentral/answers/398012-adding-a-scatter-of-points-to-a-boxplot#answer_557928

Edited: Ernesto Salcedo on 27 Nov 2020

Open in MATLAB Online

Boxchart solution for grouped categorical data

Table with random group

count = 20;

T = table(randi(10,count,1), categorical(repmat(["papaya";"silicon"], count/2,1)),'VariableNames',["Recharges","model"])

T.idx = grp2idx(T.model); % convert categories into group indices

Boxchart

figure

hc = boxchart(T.idx, T.Recharges); % group by index

hold on

% overlay the scatter plots

for n=1:max(unique(T.idx))

hs = scatter(ones(sum(T.idx==n),1) + n-1, T.Recharges(T.idx == n),"filled",'jitter','on','JitterAmount',0.1);

hs.MarkerFaceAlpha = 0.5;

end

set(gca,"XTick", unique(T.idx),"XTickLabel",categories(T.model))

Adding a scatter of points to a boxplot (15)

0 Comments

Show -2 older commentsHide -2 older comments

Sign in to comment.

Sign in to answer this question.

See Also

Categories

MATLABGraphics2-D and 3-D PlotsData Distribution PlotsScatter Plots

Find more on Scatter Plots in Help Center and File Exchange

Tags

  • scatter
  • boxplot

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

An Error Occurred

Unable to complete the action because of changes made to the page. Reload the page to see its updated state.


Adding a scatter of points to a boxplot (16)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom(English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本Japanese (日本語)
  • 한국Korean (한국어)

Contact your local office

Adding a scatter of points to a boxplot (2024)

FAQs

How do you add data points to a box plot? ›

You can do this a few different ways. After generating the box plot in graph builder you can right click the graph, select add, then select points. Alternatively, you can add the points on top of the box plot by dragging the icon with points (in the pallete above the graph) on top of the graph.

How do I add dots to a boxplot? ›

Single box plot with points

You need to pass the data you used to create your box plot, set the "jitter" method to add random noise over the data points, avoiding overplotting, set the desired aesthetics arguments such as pch or col and add = TRUE so the points are added over the previous plot.

How do you add labels to scatter points? ›

To add data labels to a scatter plot, just right-click on any point in the data series you want to add labels to, and then select “Add Data Labels…” Excel will open up the “Format Data Labels” pane and apply its default settings, which are to show the current Y value as the label.

What is the use of a scatter plot and a box plot? ›

Scatter plots, to show relationships among numerical variables. Line graphs, to show change over time. Histograms, to show data distributions. Boxplots, to show between-group and within-group variation.

How do you add data points to a graph? ›

In order to plot points on a graph:
  1. Identify the horizontal ( x-value) and vertical position ( y-value) of the ordered pair.
  2. Follow the gridlines until the two values meet and draw a point.
  3. Identify which axis or quadrant the point(s) is in.

What are the 5 data points in a box plot? ›

A box and whisker plot—also called a box plot—displays the five-number summary of a set of data. The five-number summary is the minimum, first quartile, median, third quartile, and maximum. In a box plot, we draw a box from the first quartile to the third quartile. A vertical line goes through the box at the median.

What are the extra dots on a box plot? ›

Lines extend from each box to capture the range of the remaining data, with dots placed past the line edges to indicate outliers.

How to make a scatter box plot in Excel? ›

Create a scatter chart
  1. Copy the example worksheet data into a blank worksheet or open the worksheet that contains the data you want to plot in a scatter chart. ...
  2. Select the data you want to plot in the scatter chart.
  3. Click the Insert tab, and then click Insert Scatter (X, Y) or Bubble Chart.
  4. Click Scatter.

How do you add labels to a box plot? ›

Select the desired label type in the Label type field, such as Samples Count. Then, check the box next to the Display option to add the specific label to the plot. To display multiple types of labels, open each label section and check the box next to the Display option.

How do you connect dots on a scatter plot? ›

Graphing two lines using a scatter plot with connected lines
  1. Highlight all the data as well as the table column labels that you want to plot.
  2. Go to the “Insert” Tab.
  3. Find the “Charts” Section.
  4. Click on one of the Scatter Plot icon and select one that also connects the dots with a line.

How do you add data labels to certain points? ›

To label one data point, after clicking the series, click that data point. In the upper right corner, next to the chart, click Add Chart Element > Data Labels. To change the location, click the arrow, and choose an option. If you want to show your data label inside a text bubble shape, click Data Callout.

How to make a scatter plot? ›

Mark each data point on your scatter plot.

Find the location on the x-axis where the independent variable will be, and then move upwards in a straight line until it intersects with the dependent variable on the y-axis. Mark a dot or a cross where the 2 variables meet, and repeat for every variable you've collected.

How to make a scatter plot comparing two sets of data? ›

How to create a scatter plot in Excel
  1. Select two columns with numeric data, including the column headers. In our case, it is the range C1:D13. ...
  2. Go to the Inset tab > Chats group, click the Scatter chart icon, and select the desired template. To insert a classic scatter graph, click the first thumbnail:
Mar 16, 2023

When should you use a scatter plot? ›

Scatter plots' primary uses are to observe and show relationships between two numeric variables. The dots in a scatter plot not only report the values of individual data points, but also patterns when the data are taken as a whole. Identification of correlational relationships are common with scatter plots.

How do you add data points to a map? ›

Search for places
  1. On your computer, sign in to My Maps.
  2. Open or create a map.
  3. In the search bar, type the name or address of a place.
  4. Click one of the results on the map.
  5. If the result is what you want, click Add to map.

What are the points on a box plot? ›

In box plots, dots are outliers. This is not particular to Seaborn or any other tool; it is generical to visualization in statistics. The outliers are points that stay out of the interval [Q1-1.5*IQR; Q3+1.5*IQR] , with: Q1 = Quartile 1 (25th percentile)

How to do a box plot with data? ›

If you're doing statistical analysis, you may want to create a standard box plot to show distribution of a set of data. In a box plot, numerical data is divided into quartiles, and a box is drawn between the first and third quartiles, with an additional line drawn along the second quartile to mark the median.

References

Top Articles
Movie Box Office Mojo
Rebecca Mcnamee-Croft
Texas Roadhouse On Siegen Lane
M3Gan Showtimes Near Cinemark Movies 8 - Paris
Wal-Mart 140 Supercenter Products
Stolen Touches Neva Altaj Read Online Free
LensCrafters Review for September 2024 | Best Contact Lens Stores
15:30 Est
Melia Nassau Beach Construction Update 2023
Cold War Brainpop Answers
St Vrain Chain Gang
What Was D-Day Weegy
Guy I'm Talking To Deleted Bumble
Thompson Center Thunderhawk Parts
Premier Auto Works-- The House Of Cash Car Deals
Leaf Blower and Vacuum Vacuum Hoses
Immobiliare di Felice| Appartamento | Appartamento in vendita Porto San
Punishment - Chapter 1 - Go_mi - 鬼滅の刃
Jetblue Live Flight Tracker
Naval Academy Baseball Roster
Kawasaki Ninja® 500 | Motorcycle | Approachable Power
Eurail Pass Review: Is It Worth the Price?
Telegram Voyeur
Peoplesoft Oracle Americold Login
Scrap Metal Prices in Indiana, Pennsylvania Scrap Price Index,United States Scrap Yards
Advance Auto Parts Near Me Open Now
Poker News Views Gossip
25+ Irresistible PowerXL Air Fryer Recipes for Every Occasion! – ChefsBliss
Ssbbw Coomer
3 Izzy Ln, Kittery, ME 03904 - MLS 1603480 - Coldwell Banker
Oklahoma Scratch Off Remaining Prizes
SimpliSafe Home Security Review: Still a Top DIY Choice
Dr Yakubu Riverview
Craigslist Cars And Trucks Delaware
Rbgfe
Jbz Inlog
Walmart Careers Application Part Time
Brooklyn Park City Hall
Az610 Flight Status
Nsfw Otp Prompt Generator Dyslexic Friendly
O'reillys Parts Store
Watkins Brothers Funeral Homes Macdonald Chapel Howell Obituaries
Molly Leach from Molly’s Artistry Demonstrates Amazing Rings in Acryli
Baroque Violin Shop Cincinnati Oh
Dawat Restaurant Novi
Saryn Prime Build 2023
Why Did Jen Lewis Leave Wavy 10
The many times it was so much worse
La tarifa "Go Hilton" para los amigos y familiares de los miembros del equipo - Lo que debe saber
Mi Game Time
Union Corners Obgyn
Sdn Michigan State Osteopathic 2023
Latest Posts
Article information

Author: Saturnina Altenwerth DVM

Last Updated:

Views: 6178

Rating: 4.3 / 5 (44 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Saturnina Altenwerth DVM

Birthday: 1992-08-21

Address: Apt. 237 662 Haag Mills, East Verenaport, MO 57071-5493

Phone: +331850833384

Job: District Real-Estate Architect

Hobby: Skateboarding, Taxidermy, Air sports, Painting, Knife making, Letterboxing, Inline skating

Introduction: My name is Saturnina Altenwerth DVM, I am a witty, perfect, combative, beautiful, determined, fancy, determined person who loves writing and wants to share my knowledge and understanding with you.