Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9231797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:09:33+00:00 2026-06-18T06:09:33+00:00

I have some data and am trying to make boxplots with an overlay of

  • 0

I have some data and am trying to make boxplots with an overlay of jittered points. My issue is with the points, so we’ll stick with that.

Here’s the data:

> dput(test)
structure(list(var1 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 
8L, 9L, 9L, 9L, 9L, 9L, 9L, 9L), .Label = c("A", "B", "C", "D", 
"E", "F", "G", "H", "I"), class = "factor"), var2 = structure(c(1L, 
2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 
4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 
1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L), .Label = c("V1", 
"V2", "V3", "V4", "V5", "V6", "V7"), class = "factor"), response1 = c(5L, 
6L, 5L, 5L, 5L, 5L, 4L, 6L, 6L, 5L, 5L, 6L, 6L, 4L, 1L, 1L, NA, 
1L, NA, NA, 1L, 1L, 1L, NA, 1L, NA, NA, 1L, 5L, 5L, 4L, 5L, 3L, 
2L, 3L, 1L, 1L, NA, 1L, NA, NA, 1L, NA, NA, 2L, NA, 3L, 1L, NA, 
NA, NA, 4L, NA, 4L, 5L, NA, NA, NA, 1L, NA, 1L, 1L, NA), response2 = c(2L, 
2L, 2L, 2L, 2L, 2L, 4L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 5L, 5L, NA, 
5L, NA, NA, 5L, 5L, 5L, NA, 5L, NA, NA, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, NA, 5L, NA, NA, 5L, NA, NA, 5L, NA, 5L, 5L, NA, 
NA, NA, 5L, NA, 5L, 5L, NA, NA, NA, 5L, NA, 5L, 5L, NA), response3 = c(4L, 
5L, 1L, 1L, 4L, 1L, 1L, 4L, 5L, 1L, 1L, 5L, NA, 1L, 4L, NA, NA, 
NA, 3L, 2L, NA, 4L, NA, NA, NA, 3L, NA, NA, 4L, NA, 1L, NA, 3L, 
NA, 2L, 4L, NA, NA, NA, NA, NA, NA, NA, 2L, 1L, 1L, NA, NA, 1L, 
NA, 3L, 1L, NA, NA, NA, 1L, NA, 3L, 1L, NA, NA, NA, 1L)), .Names = c("var1", 
"var2", "response1", "response2", "response3"), class = "data.frame", row.names = c(NA, 
-63L))

I used reshape2 to melt my data for faceting/simiplification of plot command:

library(reshape2)
test_melted <- melt(test, id.var = c("var1", "var2"), na.rm = T)

And here was the plot I created:

library(ggplot2)
p <- ggplot(test_melted, aes(x = var1, y = value)) + geom_point()
p <- p + facet_grid(~variable) + coord_flip()
p <- p + geom_jitter(position = position_jitter(width=0.2, height = 0.2))
p

That yields this:

enter image description here

Looked normal enough, but then I noticed it seemed like there were more points per facet/factor level than there should be. I narrowed down to just one level for var1

test_subset <- test_melted[test_melted$var1 == "E", ]

nrow(test_subset)
[1] 18

summary(test_subset)
      var1    var2        variable     value  
 E      :18   V1:3   response1:7   Min.   :1  
 A      : 0   V2:2   response2:7   1st Qu.:3  
 B      : 0   V3:3   response3:4   Median :5  
 C      : 0   V4:2                 Mean   :4  
 D      : 0   V5:3                 3rd Qu.:5  
 F      : 0   V6:2                 Max.   :5  
 (Other): 0   V7:3 

So, we should have 18 total points plotted (7 for response1, 7 for response2, and 4 for response3. Let’s try it:

p <- ggplot(test_subset, aes(x = var1, y = value)) + geom_point()
p <- p + facet_grid(~variable) + coord_flip()
p <- p + geom_jitter(position = position_jitter(width=0.2, height = 0.2))
p

enter image description here

I count 11 points in the response1 facet, 8 in response2, and 8 in response3.

This has got to be something silly I’m missing. I’ve done plenty of faceting with dot plots and just never had this happen (or never noticed!).

Things I tried

  • Removing coord_flip()
  • test_subset <- droplevels(test_subset) in case empty factor levels were messing with something
  • Playing with facet_grid(~variable) vs. facet_grid(.~variable) vs. facet_grid(variable~) vs. facet_grid(variable~.)

As one last note, I get different numbers of points depending on whether or not I facet. With faceting, I get 11 + 8 + 8 = 27, if I remove the facet_grid(~variable), I get 23.

Thanks for any suggestions!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T06:09:34+00:00Added an answer on June 18, 2026 at 6:09 am

    The problem is not due to faceting, it is due to the fact that use two geoms in your plot. So geom_point will draw your points all in one place, and then geom_jitter will draw them once more, at random positions. That’s why you can see one more point in each plot.

    If you remove the call to geom_point everything is back to normal :

    p <- ggplot(test_subset, aes(x = var1, y = value))
    p <- p + facet_grid(~variable) + coord_flip()
    p <- p + geom_jitter(position = position_jitter(width=0.2, height = 0.2))
    p
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data about a day's events that I'm trying to visualise as
i have a simple template that i populate with some data then im trying
I have a form that is trying to insert some data into an SQL
I am trying to make some data from database available using XML, I have
I am trying to make a simple Facebook app that takes some data from
I am trying to make a Visual C++ 2008 program that plots some data
So, I'm trying to use Doctrine to retrieve some data. I have some basic
I have some very ugly data I am trying to massage. It consist of
I have created a web service which returns some data and am trying to
I have been trying all day to get some data properly formatted in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.