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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:41:46+00:00 2026-05-24T21:41:46+00:00

I just came across this code that lets me plot multiple ordinates (I know

  • 0

I just came across this code that lets me plot multiple ordinates (I know it is a bad notion in the community but I need to do it to compare different metrics). Since this cannot be done inherently in ggplot2, I was wondering if I can adapt the following code to do what I need:

twoord.plot(2:10,seq(3,7,by=0.5)+rnorm(9),
  1:15,rev(60:74)+rnorm(15),xlab="Sequence",
  ylab="Ascending values",rylab="Descending values",
  main="Plot with two ordinates - bars on the left",
  type=c("bar","l"),lcol=3,rcol=4)

plots the following:

enter image description here

What I am looking for is to plot multiple bars side to side. I tried replacing type=c("bar", "l") with type=c("bar", "bar") but that gave me overlapping bars. The exact data I want to plot is the following:

Category    SubCat  Value
A           Cat1    0.1
B           Cat1    0.2
A           Cat2    0.3
B           Cat2    0.24
A           Cat3    13
B           Cat3    41
A           Cat4    60
B           Cat4    146

I want (A,B) under (Cat1,Cat2) to have the scale on the left, and (A,B) under (Cat3, Cat4) to have the scale on the right and all bars under A and B to be grouped together respectively. Can someone please tell me how to do this?

  • 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-24T21:41:47+00:00Added an answer on May 24, 2026 at 9:41 pm

    The following is probably as close as you’re going to get using ggplot2:

    d <- read.table(textConnection("Category    SubCat  Value
    A           Cat1    0.1
    B           Cat1    0.2
    A           Cat2    0.3
    B           Cat2    0.24
    A           Cat3    13
    B           Cat3    41
    A           Cat4    60
    B           Cat4    146"),header = TRUE, sep="")
    
    d$grp <- rep(c('Cat1 - Cat2','Cat3 - Cat4'), each = 4)
    ggplot(d,aes(x = Category, y = Value)) + 
        facet_wrap(~grp, scales = "free_y") + 
        geom_bar(aes(fill = SubCat), position = "dodge")
    

    enter image description here

    This achieves a “dual y axis” by faceting and allowing ggplot2 to set the axes separately. I’m sure it’s possible to get something closer to what you want using base graphics, but it will take some more thought.

    EDIT

    And here’s a hack using the twoord.plot. Took quite a bit of fiddling, but I’ve never used that function, so there may be an easier way:

    par(xaxt = "n") 
    twoord.plot(ly = d$Value[1:4],ry = d$Value[5:8], rx = c(9,11,13,15), lx = c(1,3,5,7),
                type = c('bar','bar'), 
                xlim = c(0,16),
                lylim = c(0,0.35),rylim = c(12,150))
    par(xaxt="s")           
    axis(1, at = c(1,3,5,7,9,11,13,15),
            labels = paste(d$Category,d$SubCat,sep=""),
            las = 3)
    

    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 just came a cross this nice code that makes this scatter matrix plot:
I just came across code that looks like this: if (foo == bar){}else{ }
I just came across this code and a few Google searches turn up no
Just came across this quote in a book on OOP that I'm reading, A
I just came across a C++ SDK that makes heavy use of this really
Some old code that I just came across: MLIST * new_mlist_link() { MLIST *new_link
It's easy! I just came across this blog post by Rudi Grobler that says
I just came across some code that overrides ToString() and returns some critical information
I was just browsing Sizzle's source code and I came across this line of
HI, I just came across good link and used that in my code.. how

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.