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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:20:02+00:00 2026-06-01T01:20:02+00:00

I have the following data test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10)) I would like a barplot with

  • 0

I have the following data

test<-data.frame(group=1:10, var.a=rnorm(n=10,mean=500,sd=20), var.b=runif(10))

I would like a barplot with 2 y axis (one for var.a, one for var.2). Each group (x axis, 1:10) should have 2 bars next to each other, one for var.a and one for var.b.

I cannot use one y-axis because of the difference morder of magnitude of var.a and var.b

Is this possible with base R?

Thank you

  • 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-01T01:20:03+00:00Added an answer on June 1, 2026 at 1:20 am

    To use the graphics package in R, one could create new variables as the values in var.a and var.b converted into proportions of the maximum values in the respective variable:

    test <- data.frame(group = 1:10, var.a = rnorm(n = 10, mean = 500, sd = 20),
      var.b = runif(10))
    
    funProp <- function(testCol) {
        test[, testCol]/max(test[, testCol])
    }
    
    test$var.a.prop <- funProp("var.a")
    test$var.b.prop <- funProp("var.b")
    

    Then draw the plot using barplot() without the axes:

    barplot(t(as.matrix(test[, c("var.a.prop", "var.b.prop")])), beside = TRUE,
      yaxt = "n", names.arg = test$group)
    

    Then add the axes on the left and the right using the original value ranges for the labels (the labels argument) and the proportional value ranges to place the labels on the axes (the at argument) (this part is not pretty, but it gets the job done):

    axis(2, at = seq(0, max(test$var.a.prop), length.out = 10),
      labels = round(seq(0, max(test$var.a), length.out = 10)))
    
    axis(4, at = seq(0, max(test$var.b.prop), length.out = 10),
      labels = round(seq(0, max(test$var.b), length.out = 10), 2))
    

    (Sorry for the lack of an image)

    EDIT:

    To get the axes a bit prettyer,

    myLeftAxisLabs <- pretty(seq(0, max(test$var.a), length.out = 10))
    myRightAxisLabs <- pretty(seq(0, max(test$var.b), length.out = 10))
    
    myLeftAxisAt <- myLeftAxisLabs/max(test$var.a)
    myRightAxisAt <- myRightAxisLabs/max(test$var.b)
    
    barplot(t(as.matrix(test[, c("var.a.prop", "var.b.prop")])),
      beside = TRUE, yaxt = "n", names.arg = test$group,
      ylim=c(0, max(c(myLeftAxisAt, myRightAxisAt))))
    
    axis(2, at = myLeftAxisAt, labels = myLeftAxisLabs)
    
    axis(4, at = myRightAxisAt, labels = myRightAxisLabs)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data frame: Test <- data.frame(Species = c(A,B,C,D), WB1=c(0.1,1.1,0.9,1.2), WB2=c(1, 0.8,
I have the following test data frame : test <- read.table(header = TRUE, text
I have the following data in my database (comma separated strings): word, test, hello
Let say I have the following data in R. training = factor(c(1,1,3,2,1,3,2,34,67,34)) test =
I have the following test code use Data::Dumper; my $hash = { foo =>
I have loaded the following test data: name, age,gender John, 33,m Sam, 33,m Julie,33,f
I have the following response: { data: [ { name: This is a test
I have a set of data such as the following: annual_exp<-as.data.frame(c(6000,4200,240001,750,20000,3470,10500,2400,2280,36000,3600,20000,2000,12000,1200,3000,4500,64000)) annual_exp<-as.data.frame(annual_exp) I want
in my webapp I have a variable like this var data = { getItem:
i have the following data root root/blue root/blue/temp root/main root/main/dev root/main/back root/etc/init root/etc/init/dev root/etc/init/test

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.