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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:33:51+00:00 2026-05-29T20:33:51+00:00

I have a dataframe with 3 columns $x — at http://pastebin.com/SGrRUJcA $y — at

  • 0

I have a dataframe with 3 columns

  • $x — at http://pastebin.com/SGrRUJcA
  • $y — at http://pastebin.com/fhn7A1rj
  • $z — at http://pastebin.com/VmVvdHEE

that I wish to use to generate a stacked barplot. All of these columns hold integer data. The stacked barplot should have the levels along the x-axis and the data for each level along the y-axis. The stacks should then correspond to each of $x, $y and $z.

UPDATE: I now have the following:

counted <- data.frame(table(myDf$x),variable='x')
counted <- rbind(counted,data.frame(table(myDf$y),variable='y'))
counted <- rbind(counted,data.frame(table(myDf$z),variable='z'))
counted <- counted[counted$Var1!=0,]  # to get rid of 0th level??

stackedBp <- ggplot(counted,aes(x=Var1,y=Freq,fill=variable))
stackedBp <-  stackedBp+geom_bar(stat='identity')+scale_x_discrete('Levels')+scale_y_continuous('Frequency')
stackedBp

which generates:

stack plot.

Two issues remain:

  1. the x-axis labeling is not correct. For some reason, it goes: 46, 47, 53, 54, 38, 40…. How can I order it naturally?

  2. I also wish to remove the 0th label.

I’ve tried using +scale_x_discrete(breaks = 0:50, labels = 1:50) but this doesn’t work.

NB. axis labeling issue: Dataframe column appears incorrectly sorted

  • 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-05-29T20:33:52+00:00Added an answer on May 29, 2026 at 8:33 pm

    Not completely sure what you’re wanting to see… but reading ?barplot says the first argument, height must be a vector or matrix. So to fix your initial error:

    myDf <- data.frame(x=sample(1:10,100,replace=T),y=sample(11:20,100,replace=T),z=1:10)
    barplot(as.matrix(myDf))
    

    If you provide a reproducible example and a more specific description of your desired output you can get a better answer.

    Or if I were to guess wildly (and use ggplot)…

    myDf <- data.frame(x=sample(1:10,100,replace=T),y=sample(11:20,100,replace=T),z=1:10)
    myDf.counted<- data.frame(table(myDf$x),variable='x')
    myDf.counted <- rbind(myDf.counted,data.frame(table(myDf$y),variable='y'))
    myDf.counted <- rbind(myDf.counted,data.frame(table(myDf$z),variable='z'))
    
    ggplot(myDf.counted,aes(x=Var1,y=Freq,fill=variable))+geom_bar(stat='identity')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a dataframe with three columns -- $x -- at http://pastebin.com/SGrRUJcA $y -- at
I have a dataframe with 6 columns and many rows that includes positions for
I have a dataframe with a column of integers that I would like to
I have a dataframe of 9 columns consisting of an inventory of factors. Each
I have a big dataframe with columns such as: ID, time, OS, IP Each
Say I have a dataframe df with two or more columns, is there an
I have a dataframe (14.5K rows by 15 columns) containing billing data from 2001
I have a dataframe where one of the columns contains a set of names.
I have a dataframe that I want to reshape; my reshape code: matchedlong <-
I have a dataframe with columns labeled A,B & C. I want to add

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.