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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:18:43+00:00 2026-06-13T16:18:43+00:00

I am struggling to display two barcharts side by side with the same scale

  • 0

I am struggling to display two barcharts side by side with the same scale

My code looks like this

library(ggplot2)
library(gridExtra)
#dataframe definition
rm(list=ls(all=TRUE))
mydata <- data.frame(a=1:10,b=c('yes','no'),c=seq(2,20,2))

plot1<- ggplot(mydata, aes(x=factor(mydata$b), y=100*a), order=f, fill=grey) + 
  stat_summary(fun.y="mean", geo    m="bar", colour="black")+xlab("Factor b") + 
  ylab("Value of a")    

plot2<- ggplot(mydata, aes(x=factor(mydata$b), y=c), order=f) + 
  stat_summary(fun.y="mean", geom="bar", colour="black")+xlab("Factor b") + 
  ylab("Value of b")    

grid.arrange(plot1, plot2, ncol=2)

That produces the following image.

Image output from ggplot2

I want to position them in a way the vertical axis has the same scale for both of the barcharts.
I couldn’t find any documentation on the gridExtra manual.

  • 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-13T16:18:44+00:00Added an answer on June 13, 2026 at 4:18 pm

    What about something like this?

    library(ggplot2)
    library(reshape2)
    
    mydata <- data.frame(a=1:10,b=c('yes','no'),c=seq(2,20,2))
    df <- melt(mydata, id.vars="b")
    df[which(df$variable=="a"),]$value <- df[which(df$variable=="a"),]$value * 100
    ggplot(df, aes(factor(b), value))  + 
      stat_summary(fun.y="mean", geom="bar", colour="black") + facet_grid(.~variable)
    
    
    # If you need free scales, then:
    
    ggplot(df, aes(factor(b), value))  + 
      stat_summary(fun.y="mean", geom="bar", colour="black") + 
      facet_wrap( ~variable, scales = "free_y")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling to compare two php variables to display or not display some text
I'm struggling a bit with this CSS-issue: http://jsfiddle.net/timkl/JbEX8/ I want two divs to align
This is really a two part question . I'm struggling with two problems that
I'm struggling with this. I've got it to display most of the list, but
I'm struggling to display a watermark (so called placeholder) on my MVC3 form inputs.
Struggling with a bit of a mystery regarding a ghost like JESSIONID Cookie. I'm
Im struggling with this one. I have a list of items and on a
Been struggling with this simple selector problem a couple of hours now and must
im struggling with syntax here: hopefully this question is v simple, im just miising
I'm struggling to find a way to code a site according to our strange

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.