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

  • Home
  • SEARCH
  • 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 7723971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:34:39+00:00 2026-06-01T04:34:39+00:00

I have some data that I want to display as a box plot using

  • 0

I have some data that I want to display as a box plot using ggplot2. It’s basically counts, stratified by two other variables. Here’s an example of the data (in reality there’s a lot more, but the structure is the same):

TAG Count Condition
A     5         1
A     6         1
A     6         1
A     6         2
A     7         2
A     7         2
B     1         1
B     2         1
B     2         1
B    12         2
B     8         2
B    10         2
C    10         1
C    12         1
C    13         1
C     7         2
C     6         2
C    10         2

For each Tag, there are a fixed number of observations in condition 1, and condition 2 (here it’s 3, but in the real data it’s much more). I want a box plot like the following (‘s’ is a dataframe arranged as above):

ggplot(s, aes(x=TAG, y=Count, fill=factor(Condition))) + geom_boxplot()

Plot of example data

This is fine, but I want to be able to order the x-axis by the p-value from a Wilcoxon test for each Tag. For example, with the above data, the values would be (for the tags A,B, and C respectively):

> wilcox.test(c(5,6,6),c(6,7,7))$p.value
[1] 0.1572992
> wilcox.test(c(1,2,2),c(12,8,10))$p.value
[1] 0.0765225
> wilcox.test(c(10,12,13),c(7,6,10))$p.value
[1] 0.1211833

Which would induce the ordering A,C,B on the x-axis (largest to smallest). But I don’t know how to go about adding this information into my data (specifically, attaching a p-value at just the tag level, rather than adding a whole extra column), or how to use it to change the x-axis order. Any help greatly appreciated.

  • 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-01T04:34:41+00:00Added an answer on June 1, 2026 at 4:34 am

    Here is a way do it. The first step is to calculate the p-values for each TAG. We do this by using ddply which splits the data by TAG, and calculates the p-value using the formula interface to wilcox.test. The plot statement reorders the TAG based on its p-value.

    library(ggplot2); library(plyr)
    dfr2 <- ddply(dfr, .(TAG), transform, 
      pval = wilcox.test(Count ~ Condition)$p.value)
    
    qplot(reorder(TAG, pval), Count, fill = factor(Condition), geom = 'boxplot', 
      data = dfr2)
    

    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 a JTable that I want to use to display some data (a
I have some data generated in MATLAB that I want to process using Perl.
I have some text data from database that I want to display it on
I have some data that I want to store somewhere in my Rails app
I have some data that has various attributes and I want to hierarchically group
I have some data. I want to go through that data and change cells
I have a controller with that I want to pass off some data to
I have some hierarchical data that I need display as a table, can I
I have some data that I want to present in a FlowDocument . This
I have some data that won't printf.... echo works, but not printf There is

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.