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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:16:01+00:00 2026-06-02T20:16:01+00:00

I am trying to combine two graphs in R (using lattice), a boxplot and

  • 0

I am trying to combine two graphs in R (using lattice), a boxplot and a barchart. I want both the box and the bar to be vertical. For the barchart, I would use the horizontal=FALSE option. But for the boxplot I know I cannot use that option. From this post, I will use the horizontal boxplot and rotate it to vertical.

So not I have one rotated graph and one un-rotated graph, that I want to combine. Here is what I tried:

library(lattice)

mydata <- data.frame(
      methods = c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15),
      savings = c(38.1677115678,40.0271480111,3.0658967834,8.55162576,54.5599157619,52.5120636113,6.0234897727,8.1064331259,63.9865435108,64.7867073871,3.8590732507,7.7348316433,49.7059967478,53.8979070884,2.497892375)
      )
attach(mydata)
png("test.png", width=800, height=600)

h1 = barchart( savings ~ methods, data=mydata, horizontal=FALSE,
               ylab = "", main = "Predicted Savings",
               scales=list(y=list(labels=c("","","","","","","","","","","","","",""),tick.number=10))
             )

require(grid)
grid.newpage()
pushviewport(viewport(angle = 90, name = "VP"))
h2 =  bwplot(savings, xlim=c(0,100),
      xlab=list(label="predicted savings", fontsize=14),
      scales = list(x = list(tick.number=10)), draw.in = "VP"
      )
print( h2,newpage=FALSE, position=c(0.15, 0.95, 0.85, 1.2), more=TRUE)
print(h1, newpage=FALSE, position=c(0.20, 0.00, 1.00, 1.0), more=TRUE)

And here is the result. I got the barchart also rotated. I thought, since I do not use draw.in = "VP" option when I draw the barchart, then I will not get it rotated. But apparently I am wrong.
Is there a way I can get the barchart below un-rotated.

enter image description here

  • 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-02T20:16:02+00:00Added an answer on June 2, 2026 at 8:16 pm

    Currently you are plotting both plots in the rotated viewport. You need either to go upViewport() before plotting h1, or simply plot it before pushing the viewport:

    grid.newpage()
    print(h1, newpage=FALSE, position=c(0.20, 0.00, 1.00, 1.0), more=TRUE)
    pushViewport(viewport(angle = 90, name = "VP"))
    h2 =  bwplot(savings, xlim=c(0,100),
          xlab=list(label="predicted savings", fontsize=14),
          scales = list(x = list(tick.number=10)), draw.in = "VP"
          )
    print( h2,newpage=FALSE, position=c(0.15, 0.95, 0.85, 1.2), more=TRUE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I am trying to combine two transparent png-24 images, both size 400width, 150height.
I'm trying to combine to two tables, and I want the smallest id where
I have two PNGs that I am trying to combine into a PDF using
I'm trying to combine data from two tables in MySQL with PHP. I want
I'm trying to combine two Google App Engine datastore results. Because I then want
I'm trying to combine two textures in HLSL - specifically, I want to take
I am trying to combine the two into a single statment, I would even
I am trying to use array_combine to combine two multi-dimensional arrays, but somehow not
I'm trying to figure out how to use StateT to combine two State state
How would I combine two elements to use the focus function? #s_type and #s_ctry

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.