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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:11:46+00:00 2026-06-14T21:11:46+00:00

I am trying to make a (1 row, 3 column) array of barplots that

  • 0

I am trying to make a (1 row, 3 column) array of barplots that all have the same bar width.

All three bar plots have a different number of observations and hence the width of the bars end up different for each plot (i.e. plot with the most observations has the narrowest bars and the plot with the fewest observations has the widest bars). I understand from the barplot {graphics} R documentation that,

“Specifying a single value will have no visible effect unless xlim is specified”

However, my x labels are strings, so I’m not sure how to specify xlim. I don’t mind if my plots are different widths, but do I need to specify this somehow?

Here is some fake data and the code I am using… thank you for your help.

height4plot1 <- c(1,6,9,2,3,10,7,15)
names4plot1 <- c("P1","P2","P3","P4","P5","P6","P7","P8")

height4plot2 <- c(5,4,10,2)
names4plot2 <- c("M1","M2","M3","M4")

height4plot3 <- c(4,12)
names4plot3 <0 c("U1","U2")

par(mfrow=c(1,3),
    mar=c(10,5,2,1),
    cex.axis=0.7,
    mgp=c(3,0.5,0))
barplot(height4plot1,
    names.arg=names4plot1,
    las=3,
    axes=TRUE,
    axisnames=TRUE,
    ylab="YLAB",
    ylim=ylim,
    plot=TRUE,
    main="PLOT1",
    width=1)
barplot(height4plot2,
    names.arg=names4plot2,
    las=3,
    axes=TRUE,
    axisnames=TRUE,
    ylim=ylim,
    plot=TRUE,
    main="PLOT2",
    width=1)
barplot(height4plot3,
    names.arg=names4plot3,
    las=3,
    axes=TRUE,
    axisnames=TRUE,
    ylim=ylim,
    plot=TRUE,
    main="PLOT3",
    width=1)
  • 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-14T21:11:47+00:00Added an answer on June 14, 2026 at 9:11 pm

    Without the variables like height4plot1 etc. it is harder to test your code and modifications, but here are some possibilities:

    You can specify width=0.8 for each plot and xlim=c(0,maxnum) where maxnum is the maximum numbers of bars in the different plots. This will leave an empty section in each of the smaller bar plots.

    You could pad the shorter vectors of heights with NA until they are all the same length (this would still give the empty sections).

    You could concatenate your 3 vectors together and make a single boxplot, possibly coloring the 3 groups differently to help distinquish them. The abline function can be used to add divider lines between the groups (and see the space argument to barplot, or include an ‘NA’ as divider to give more space between the groups). You can use the return value to help in placing titles above each group.

    You can use layout instead of par to set up your 3 plotting areas to have different widths, but getting the exact ratios of widths to give the exact same size bars will not be simple (you may get close with trial and error though). If you really want this route then grconvertX and optim may help.

    I would suggest the 2nd option above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make all rows have a hover background except the header row.
I'm trying make an entity with doctrine that has three associations with other entities
I have a TextView that I am trying to make display a 2d character-based
I'm trying to make a tile map in libgdx. I have made all the
I am trying to have a 2D Array that is 16 rows by 11
I am trying to make a row in a table link to the edit
I am trying to make a list of links, 6 links in a row.
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
I am trying to create a JTable that has a row header that looks
I'm trying to make my string a nice formatted time but the column in

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.