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 8280913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T09:51:11+00:00 2026-06-08T09:51:11+00:00

I am having trouble plotting sorted values inside each facet using ggplot2. Here is

  • 0

I am having trouble plotting sorted values inside each facet using ggplot2.

Here is the sample plotenter image description here

ggplot(data=df) + 
    geom_point(aes(y=log(count_neg,10), x= ref_name, colour=replicate)) +             
    facet_grid(condition ~ sub_groups) 

What I would like to do is sort the points in each facet by Y values. I tried the following but it didn’t work:

ggplot(data=df) + 
    geom_point(aes(sort(y=log(count_neg,10),decreading=TRUE), 
                   x= ref_name, colour=replicate)) + 
    facet_grid(condition ~ sub_groups)

Raw data here:

df<-structure(list(condition = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L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L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("A", "B"), class = "factor"), 
    ref_name = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 
    10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 
    22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L, 
    34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 
    46L, 47L, 48L, 49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 57L, 
    58L, 59L, 60L, 61L, 62L, 63L, 64L, 65L, 66L, 67L, 68L, 69L, 
    70L, 71L, 72L, 73L, 74L, 75L, 76L, 77L, 78L, 79L, 80L, 81L, 
    82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 90L, 91L, 92L, 1L, 
    2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 
    15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 25L, 26L, 
    27L, 28L, 29L, 30L, 31L, 32L, 33L, 34L, 35L, 36L, 37L, 38L, 
    39L, 40L, 41L, 42L, 43L, 44L, 45L, 46L, 47L, 48L, 49L, 50L, 
    51L, 52L, 53L, 54L, 55L, 56L, 57L, 58L, 59L, 60L, 61L, 62L, 
    63L, 64L, 65L, 66L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 
    75L, 76L, 77L, 78L, 79L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 
    87L, 88L, 89L, 90L, 91L, 92L), .Label = c("ERCC-00002", "ERCC-00003", 
    "ERCC-00004", "ERCC-00009", "ERCC-00012", "ERCC-00013", "ERCC-00014", 
    "ERCC-00016", "ERCC-00017", "ERCC-00019", "ERCC-00022", "ERCC-00024", 
    "ERCC-00025", "ERCC-00028", "ERCC-00031", "ERCC-00033", "ERCC-00034", 
    "ERCC-00035", "ERCC-00039", "ERCC-00040", "ERCC-00041", "ERCC-00042", 
    "ERCC-00043", "ERCC-00044", "ERCC-00046", "ERCC-00048", "ERCC-00051", 
    "ERCC-00053", "ERCC-00054", "ERCC-00057", "ERCC-00058", "ERCC-00059", 
    "ERCC-00060", "ERCC-00061", "ERCC-00062", "ERCC-00067", "ERCC-00069", 
    "ERCC-00071", "ERCC-00073", "ERCC-00074", "ERCC-00075", "ERCC-00076", 
    "ERCC-00077", "ERCC-00078", "ERCC-00079", "ERCC-00081", "ERCC-00083", 
    "ERCC-00084", "ERCC-00085", "ERCC-00086", "ERCC-00092", "ERCC-00095", 
    "ERCC-00096", "ERCC-00097", "ERCC-00098", "ERCC-00099", "ERCC-00104", 
    "ERCC-00108", "ERCC-00109", "ERCC-00111", "ERCC-00112", "ERCC-00113", 
    "ERCC-00116", "ERCC-00117", "ERCC-00120", "ERCC-00123", "ERCC-00126", 
    "ERCC-00130", "ERCC-00131", "ERCC-00134", "ERCC-00136", "ERCC-00137", 
    "ERCC-00138", "ERCC-00142", "ERCC-00143", "ERCC-00144", "ERCC-00145", 
    "ERCC-00147", "ERCC-00148", "ERCC-00150", "ERCC-00154", "ERCC-00156", 
    "ERCC-00157", "ERCC-00158", "ERCC-00160", "ERCC-00162", "ERCC-00163", 
    "ERCC-00164", "ERCC-00165", "ERCC-00168", "ERCC-00170", "ERCC-00171"
    ), class = "factor"), count_neg = c(468869L, 34677L, 113226L, 
    23508L, 8655L, 9319L, 210L, 25675L, 928L, 53981L, 8878L, 
    22507L, 5880L, 11756L, 21688L, 95L, 2397L, 6553L, 2533L, 
    12714L, 110L, 13520L, 71598L, 3177L, 55453L, 4157L, 3391L, 
    2740L, 144203L, 52L, 10710L, 15576L, 22028L, 5328L, 42474L, 
    1906L, 2829L, 12753L, 1207L, 351477L, 28401L, 5523L, 1166L, 
    7515L, 2773L, 17744L, 757L, 16316L, 16855L, 1236L, 16087L, 
    5447L, 358290L, 29127L, 34571L, 159457L, 630L, 46067L, 5977L, 
    22835L, 4014L, 111972L, 12372L, 5396L, 8183L, 1293L, 210L, 
    734814L, 10174L, 12838L, 39742L, 4259L, 35927L, 801L, 16309L, 
    16153L, 133685L, 8209L, 4331L, 5319L, 6029L, 3074L, 4768L, 
    2274L, 4958L, 9128L, 7243L, 2946L, 14718L, 20577L, 11257L, 
    78889L, 2407687L, 116262L, 52712L, 47998L, 10892L, 10124L, 
    479L, 19437L, 1257L, 61059L, 31119L, 25751L, 10645L, 14689L, 
    20248L, 92L, 3168L, 11003L, 3396L, 16732L, 176L, 29809L, 
    77936L, 12340L, 155159L, 5336L, 3818L, 3127L, 163497L, 66L, 
    14612L, 12687L, 25586L, 6996L, 25554L, 2284L, 3667L, 15745L, 
    1444L, 1033128L, 20087L, 17619L, 1412L, 11946L, 8014L, 19551L, 
    978L, 24182L, 22125L, 1717L, 14514L, 4564L, 903132L, 33653L, 
    39776L, 173518L, 796L, 35684L, 6524L, 62638L, 14418L, 398893L, 
    7938L, 6422L, 10595L, 1563L, 572L, 370134L, 10825L, 13837L, 
    17794L, 5164L, 43831L, 1114L, 17244L, 18924L, 171171L, 10228L, 
    5789L, 6847L, 6467L, 3582L, 6834L, 3084L, 7450L, 12474L, 
    6399L, 2390L, 22084L, 20090L, 7961L, 192521L), sub_groups = structure(c(4L, 
    4L, 1L, 2L, 3L, 4L, 4L, 3L, 1L, 1L, 4L, 3L, 2L, 1L, 2L, 1L, 
    2L, 2L, 3L, 3L, 4L, 2L, 4L, 3L, 4L, 4L, 2L, 2L, 3L, 3L, 3L, 
    4L, 2L, 4L, 1L, 2L, 4L, 3L, 2L, 3L, 2L, 3L, 4L, 4L, 4L, 4L, 
    1L, 3L, 1L, 4L, 1L, 1L, 2L, 1L, 3L, 3L, 2L, 1L, 2L, 3L, 4L, 
    3L, 1L, 2L, 3L, 1L, 2L, 1L, 1L, 1L, 1L, 4L, 2L, 2L, 3L, 1L, 
    3L, 1L, 2L, 2L, 1L, 1L, 3L, 2L, 4L, 3L, 4L, 3L, 4L, 4L, 1L, 
    2L, 4L, 4L, 1L, 2L, 3L, 4L, 4L, 3L, 1L, 1L, 4L, 3L, 2L, 1L, 
    2L, 1L, 2L, 2L, 3L, 3L, 4L, 2L, 4L, 3L, 4L, 4L, 2L, 2L, 3L, 
    3L, 3L, 4L, 2L, 4L, 1L, 2L, 4L, 3L, 2L, 3L, 2L, 3L, 4L, 4L, 
    4L, 4L, 1L, 3L, 1L, 4L, 1L, 1L, 2L, 1L, 3L, 3L, 2L, 1L, 2L, 
    3L, 4L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 1L, 1L, 1L, 4L, 2L, 2L, 
    3L, 1L, 3L, 1L, 2L, 2L, 1L, 1L, 3L, 2L, 4L, 3L, 4L, 3L, 4L, 
    4L, 1L, 2L), .Label = c("A", "B", "C", "D"), class = "factor")), .Names = c("condition", 
"replicate", "ref_name", "count_neg", "sub_groups"), row.names = c(NA, 
184L), class = "data.frame")
  • 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-08T09:51:12+00:00Added an answer on June 8, 2026 at 9:51 am

    Try this:

    df$ref_name <- reorder(df$ref_name,-log(df$count_neg,10))    
    
    ggplot(data=df) + 
        geom_point(aes(y=log(count_neg,10), x= ref_name, colour=replicate)) +             
        facet_grid(condition ~ sub_groups) 
    

    or omit the minus sign if you want the opposite ordering. This orders the x axis by the (global) y value. If you intended to order each facet separately, that is somewhat more complicated, in part because it makes the graph considerably more confusing.

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

Sidebar

Related Questions

I am relatively new to R and am having trouble plotting grouped data against
im having trouble getting a popup using javascript to show table data onmouseover when
Having trouble with each function... Will try to explain by example... In my code,
Having trouble understanding. With the following css : .bloc .field:nth-last-child(2){ ...some values... } and
Having trouble using Powershell to manipulate IP Restrictions on IIsWebVirtualDir (Virtual Directories). However, i
I'm having trouble using multiple subplots with dates on the x-axis. I'm using the
Having trouble getting my POST arrays to show all checkbox values from my form.
Having trouble using foreach to output the contents of a mysql table. The table
Having trouble finding a solution for my situation here. Sorry if this has been
Having trouble here and not quite sure how to do it. I've attempted jQuery

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.