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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:36:31+00:00 2026-06-09T08:36:31+00:00

I have the following data, and am having some issues with the y axis

  • 0

I have the following data, and am having some issues with the y axis ordering =

> str(dat)
'data.frame':   3678 obs. of  41 variables:
 $ highest_bid                 : Factor w/ 140 levels "\\N","0","10",..: 2 2 2 2 2 2 2 2 2 2 ...
 $ age_of_oldest_driver        : Factor w/ 75 levels "18","19","20",..: 66 11 33 24 57 3 17 5 32 22 ...

When I plot highest bid on age, I get the desired plot but the age’s are in order of the factor, which is not what I want. The y axis goes from 180, 19, 200, 2300, 25, 230, 250, etc. Because of values like 19, 25, and 2300, it throws the ordering of the y axis off. See below plot.

ggplot(dat, aes(x=factor(age_of_oldest_driver), y=highest_bid)) + 
      stat_summary(fun.y="mean", geom="bar")

Now, I generated some sample data to play around with this problem, but I can’t seem to reproduce it. Here’s what I did. Once again, this works perfectly.

df=data.frame(score=c(400,200,3000,500,751,630,554,630,100,250,330,5100,4100,800),
              age=c(18,18,23,50,19,39,19,23,22,22,40,35,22,16))
str(df)
ggplot(df, aes(x=factor(age), y=factor(score))) + geom_bar()

library(plyr)
library(ggplot2)
ggplot(ddply(df, .(age), mean), aes(x=factor(age), y=factor(score))) + geom_bar()

Any idea on what I’m doing wrong in the initial code that I published.

Thanks!!

Here’s the wrong image. Notice the y-axis.

enter image description here

  • 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-09T08:36:32+00:00Added an answer on June 9, 2026 at 8:36 am

    You can reorder the original factor (age) before ploting it

    df$ageord <- factor(df$age, levels = levels(factor(df$age)), ordered = TRUE )
    
    require(ggplot2)
    ggplot(df, aes(x=ageord, y = score)) + geom_bar(stat = "identity")
    

    EDIT : if it doesn’t work

    df$ageord <- factor(df$age, levels = sort(unique(df$age)), ordered = TRUE )
    
    ggplot(df, aes(x=ageord, y = score)) + geom_bar(stat = "identity")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some issues retrieving JSON data from a WCF service application
I'm having some issues with parsing CSV data with quotes. My main problem is
I'm having some issues getting the following code to compile: GLint iModelMatrix = glGetUniformLocation(m_shaderProgramID,
I am having some issues with the AudioRecord class. I have an app that
I have been having a some issues with Swing lately. I'm trying to make
I have following data frames > head(elo) date elo 1 1921-12-18 1597 2 1922-05-14
I have following data structure (simplified): A giant list of the class TestClass public
I have following data to save in database using php my data is :
I have following data in my table. alt text http://img26.imageshack.us/img26/3746/productfield.png I want to extract
I have following data in excel table r1 r2 r3 r4 r5 v1 v2

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.