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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:20:51+00:00 2026-06-17T16:20:51+00:00

Some time ago I asked a question on how to remove unused factors in

  • 0

Some time ago I asked a question on how to remove unused factors in a bar chart, and I got a useful solution for that problem, thanks to @Aaron. Now, I am facing a very similar problem, but the solution that I used in the past does not work for this case.

This is the code to reproduce the data frame that I am using:

set.seed(17)
df <- data.frame(BENCH = sprintf('bench-%s', sort(rep(letters[1:8], 4))),
                 CLASS.CFG = sprintf('class-%s',
                     c(rep('C', 4), rep('A', 4), rep('B', 8),
                       rep('C', 8), rep('A', 4), rep('D', 4))),
                 EXEC.CFG = rep(c('st', 'st', 'dyn', 'dyn'), 8),
                 METRIC = rep(c('ipc', 'pwr'), 16),
                 VALUE = runif(32))

The straightforward command to plot this data frame would be:

library(lattice)
barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, df, groups = METRIC,
         scales = list(x = list(rot = 45, relation = 'free')),
         auto.key = list(columns = 2))

As you can see, I am plotting VALUE for each BENCH constrained to every possible combination of EXEC.CFG and CLASS.CFG (that is what I mean with nested factors), and using METRIC to create groups.

This is the result that I obtain:

plot_with_gaps

Even if I use ‘free’ scales for the X axis, in the plot there are some (unnecessary) gaps between some of the bars (e.g., between bench-b and bench-g).

I tried to apply the solution that I got for my previous question in the following way:

pl1 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG,
    subset(df, CLASS.CFG == 'class-A'), groups = METRIC,
    auto.key = list(columns = 2))
pl2 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG,
    subset(df, CLASS.CFG == 'class-B'), groups = METRIC)
pl3 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG,
    subset(df, CLASS.CFG == 'class-C'), groups = METRIC)
pl4 <- barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG,
    subset(df, CLASS.CFG == 'class-D'), groups = METRIC)

pls <- c(pl1, pl2, pl3, pl4)
pls <- update(pls, scales = list(y = 'same'))
pls

And this is the result that I obtain:

wrong_plot

As you will notice, this plot is not correct. It does not respect the nested factors, mixing values from CLASS.CFG and EXEC.CFG in the panel titles.

I have been fighting with this for a while, but with no success. Does anyone know how this can be achieved? (Basically, what I am trying to obtain is a plot like the first one, but without the gaps between the bars).

  • 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-17T16:20:53+00:00Added an answer on June 17, 2026 at 4:20 pm

    To do this, you’ll need to supply both a modified prepanel function (which sets up the limits of each panel’s plotting area) and a modified panel function (which is responsible for plotting the data). In both cases, the key modification is to use x[, drop=TRUE] to drop the unused levels:

    library(lattice)
    
    barchart(VALUE ~ BENCH | EXEC.CFG + CLASS.CFG, df, groups = METRIC,
             scales = list(x = list(rot = 45, relation = 'free')),
             prepanel = function(x,y,...) {
                 xx <- x[, drop = TRUE]
                 list(xlim = levels(xx),
                      xat=sort(unique(as.numeric(xx))))
             },
             panel = function(x,y,...) {
                 xx <- x[, drop = TRUE]
                 panel.barchart(xx, y, ...)
             },
             auto.key = list(columns = 2))
    

    enter image description here

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

Sidebar

Related Questions

Some time ago I was asked the strange question how would I implement map
I asked a question some time ago on java 2d pathfinding... Pathfinding 2D Java
This question was asked quite some time ago, and while it covers possible solutions
I asked another SOAP related question some time ago, which asks for a working
This is an extension to a question which I asked some time ago. I
This is a question that I was asked on a job interview some time
I've already asked question similar to this some time ago, I thought I solved
I have asked this question some time ago Hide some datagridview checkbox cell .
Some time ago I asked a question about nested loops on SO and as
Some time ago I asked one question, and a lot of people suggested me

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.