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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:52:51+00:00 2026-06-11T08:52:51+00:00

I am trying to make a plot using barchart from lattice, but I am

  • 0

I am trying to make a plot using barchart from lattice, but I am having some issues with unused factors for a given panel. I have tried using drop.unused.levels but it seems it only drops factors when they are not used in any panel.

This is the data frame that I am using:

dm <- structure(list(Benchmark = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 
7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 1L, 
2L, 3L, 4L, 5L, 6L, 7L, 1L, 2L, 3L, 4L, 5L, 6L, 7L), class = "factor", .Label = c("416.gamess", 
"429.mcf", "436.cactusADM", "458.sjeng", "462.libquantum", "471.omnetpp", 
"482.sphinx3")), Class = structure(c(3L, 1L, 2L, 3L, 1L, 4L, 
2L, 3L, 1L, 2L, 3L, 1L, 4L, 2L, 3L, 1L, 2L, 3L, 1L, 4L, 2L, 3L, 
1L, 2L, 3L, 1L, 4L, 2L, 3L, 1L, 2L, 3L, 1L, 4L, 2L), class = "factor", .Label = c("CS", 
"PF", "PI", "PU")), Config = structure(c(1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("Disabled", 
"Shallowest", "Deepest", "StorePref", "StridedPref"), class = "factor"), 
    Perf = c(1, 0.72, 0.8, 1, 0.32, 1.16, 0.79, 1, 0.98, 1, 1, 
    0.72, 1, 0.99, 1, 0.98, 1, 1, 1.12, 0.97, 1, 1, 0.97, 1, 
    1, 0.99, 0.97, 1, 1, 1.18, 1, 1, 0.99, 0.97, 1)), .Names = c("Benchmark", 
"Class", "Config", "Perf"), row.names = c(NA, -35L), class = "data.frame")

First I attempted using barchart like this:

barchart(Perf ~ Benchmark | Class, dm, groups=Config,
         scales=list(x=list(relation='free')), auto.key=list(columns=3))

That gave me the following plot:

bad plot

As you can see, there is a gap between the benchmarks for PI, PF and CS classes. The reason is that each factor is only present in a given class, thus it is missing in all the others, and barchart might introduce a gap in the x axis.

My second attempt was to call barchart four times (one for each class):

class.subset <- function(dframe, class.name) {
    return(dframe[dframe$Class == class.name, ])
}

pl1 <- barchart(Perf ~ Benchmark, class.subset(dm, 'PI'), groups=Config)
pl2 <- barchart(Perf ~ Benchmark, class.subset(dm, 'PF'),, groups=Config)
pl3 <- barchart(Perf ~ Benchmark, class.subset(dm, 'CS'),, groups=Config)
pl4 <- barchart(Perf ~ Benchmark, class.subset(dm, 'PU'),, groups=Config)

print(pl1, split=c(1, 1, 2, 2), more = TRUE)
print(pl2, split=c(1, 2, 2, 2), more = TRUE)
print(pl3, split=c(2, 1, 2, 2), more = TRUE)
print(pl4, split=c(2, 2, 2, 2))

The plot that I got is pretty much what I want, but now I do not know how to create a single global legend for all the subplots (instead of the very same legend for each subplot):

almostgood

Ideally, I would prefer to solve the problem that I am facing using the first approach (since in that way I would also have the class name in each of the panels). However, if in the second case, it is possible to add a global legend and a title for each subplot containing the class name, that would be okay too.

  • 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-11T08:52:52+00:00Added an answer on June 11, 2026 at 8:52 am

    Here’s a quick way using latticeExtra:

    pl1 <- barchart(Perf ~ Benchmark|Class, class.subset(dm, 'PI'), groups=Config, 
                    auto.key=list(columns=3))
    pl2 <- barchart(Perf ~ Benchmark|Class, class.subset(dm, 'PF'), groups=Config)
    pl3 <- barchart(Perf ~ Benchmark|Class, class.subset(dm, 'CS'), groups=Config)
    pl4 <- barchart(Perf ~ Benchmark|Class, class.subset(dm, 'PU'), groups=Config)
    
    library(latticeExtra)
    pls <- c(pl1, pl2, pl3, pl4)
    pls <- update(pls, scales=list(y="same"))
    pls
    

    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 am trying to make a 2D density plot (from some simulation data) with
I'm trying to make a square plot (using imshow), i.e. aspect ratio of 1:1,
I am trying to make a 3D plot from x, y, z points list,
I am trying to make a contour plot of the following data using matplotlib
I was trying to make a contour plot using numpy.meshgrid and pylab.imshow(); this worked
I am trying to make a flot chart using values from MySQL database. SO
I'm trying to show a contour plot using matplotlib from a complex array. The
I'm trying to make a histogram of a vector using R. When I plot
I am trying to make a plot in R that has a portion of
I am trying to make a faceted plot in ggplot2 of the coefficients on

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.