0

I am trying to get rid of outliers in my graph that contains a boxplot and a beeswarm.

I create the boxplot with the following code:

boxplot(Lead_s ~ Group, data = g, outline = FALSE, 
    main = 'Gaze shift duration with co-occuring movement units',
    horizontal=TRUE,xlab = "Gaze lead (sec)")

With the outline=FALSE my outliers disappear.

Then, I run this code to get my data points in form of the bee swarm.

beeswarm(Lead_s ~ Group, data = g, col = 4, pch = 16, 
    add = TRUE,horizontal=TRUE,pwcol = 1 + as.numeric(Lead_s))

The boxplot with the bee swarm:

My graph

What happens is that the outliers are plotted outside of the graph. Whether I add outline=FALSE or not, the outliers are still there.

This is the data sample I plotted:

Group           Lead_s
Non-Performers  1
Non-Performers  3
Expert  18
Non-Performers  0.1
Non-Performers  0.1
Non-Performers  0.1
Non-Performers  0.2
Non-Performers  0.2
Non-Performers  0.3
Expert  0.4
Non-Performers  0.4
Non-Performers  0.4
Expert  0.5
Non-Performers  0.5
Non-Performers  0.6
Non-Performers  0.6
Non-Performers  0.7
Expert  0.8
Non-Performers  0.8
Expert  1.1
Expert  1.1
Non-Performers  1.1
Expert  1.3
Non-Performers  1.3
Non-Performers  1.4
Non-Performers  1.4
Non-Performers  1.4
Non-Performers  1.5
Expert  1.7
Expert  1.9
Non-Performers  1.9
Expert  2.1
Non-Performers  2.1
Non-Performers  2.1
Non-Performers  2.1
Non-Performers  2.3
Expert  2.5
Expert  2.7
Expert  2.7
Non-Performers  3.1
Expert  4.1
Expert  4.5
Non-Performers  5.6
Non-Performers  6.7

Any ideas how can I fix it?

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Jo-Achna
  • 315
  • 1
  • 3
  • 14
  • When asking for help you should always post a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input data so we can run and test the code. – MrFlick Mar 07 '17 at 15:39
  • @MrFlick: Data added – Jo-Achna Mar 07 '17 at 15:54
  • I cannot reproduce this in a fresh R session. Are you sure you are not making any modifications to `par()` prior to calling these functions or something? – MrFlick Mar 07 '17 at 16:01
  • @MrFlick: Have you installed the beeswarm package? Maybe this is the missing element: `install.packages('beeswarm')`. Otherwise, I don't know. I am not doing anything to the data besides what I wrote. – Jo-Achna Mar 07 '17 at 16:18

1 Answers1

0

You seem to have a non-default 'xpd' (clipping) setting. (see ?par)

To get the default behavior (not showing any points outside the plot region) you could set xpd before your plot commands:

par(xpd = FALSE)