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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:10+00:00 2026-05-27T17:15:10+00:00

From the help found here I’ve managed to create this multiplot panel: with the

  • 0

From the help found here I’ve managed to create this multiplot panel:
enter image description here
with the following code:

library(zoo)
library(ggplot2)

datos=read.csv("paterna.dat",sep=";",header=T,na.strings="-99.9")

datos$dia=as.POSIXct(datos[,1], format="%y/%m/%d %H:%M:%S")

datos$Precipitación[is.na(datos$Precipitación)]=0
xlim = as.POSIXct(c("2010-05-12 00:00:00", "2010-05-12 23:50:00"))
ylim = trunc(max(datos$Precipitación) + 5)
tmax = trunc(max(datos$Temperatura) + 5)
tmin = trunc(min(datos$Temperatura) - 5)

tmx = max(datos$Temperatura) 
tmxpos=which.max(datos$Temperatura) 
tmn = min(datos$Temperatura) 
tmnpos=which.min(datos$Temperatura) 

tmp=ggplot(data=datos,aes(x=dia, y=Temperatura)) + geom_line(colour="red") + ylab("Temperatura (ºC)") + 
xlab(" ") + scale_x_datetime(limits=xlim ,format = "%H",major='hour') + scale_y_continuous(limits = c(tmin,tmax)) + geom_text(data=datos[tmxpos,], label=tmx, vjust=-1.5, colour="red") + geom_text(data=datos[tmnpos,], label=tmn, vjust=1.5, colour="blue")

pre=ggplot(data=datos,aes(x=dia, y=Precipitación)) + geom_bar(colour="blue",stat="identity",fill="blue") +
ylab("Precipitación (l)") + xlab("Hora solar") + scale_x_datetime(limits=xlim ,format = "%H",major='hour') + scale_y_continuous(limits=c(0,ylim))

vel=ggplot(data=datos,aes(x=dia, y=Velocidad)) + geom_line(colour="brown") + ylab("Velocidad (km/h)") + xlab(" ")  + scale_x_datetime(limits=xlim ,format = "%H",major='hour') + scale_y_continuous(limits = c(0,100))

dir=ggplot(data=datos,aes(x=dia, y=Dirección)) + geom_line(colour="brown") + ylab("Dirección viento (grados)") + xlab(" ") + scale_x_datetime(limits=xlim ,format = "%H",major='hour') + scale_y_continuous(limits = c(0,360))

hum=ggplot(data=datos,aes(x=dia, y=Humedad.Relativa)) + geom_line(colour="blue") + ylab("Humedad relativa (%)") + xlab(" ") + scale_x_datetime(limits=xlim ,format = "%H",major='hour') + scale_y_continuous(limits = c(0,100))

grid.newpage()
pushViewport(viewport(layout = grid.layout(3, 2)))   
print(tmp, vp = viewport(layout.pos.row = 1, layout.pos.col = 1))         
print(vel, vp = viewport(layout.pos.row = 1, layout.pos.col = 2))
print(dir, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
print(hum, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(pre, vp = viewport(layout.pos.row = 3, layout.pos.col = 1:2))

Now I’m missing the title of the multiplot that I want to be the met. station name. I haven’t found how to set main title on grid.newpage or viewport. I’ve read about grid.arrange but couldn’t figure out how to use it in my case.

How can this be done? For sure it’s gonna be an easy question for you.

You can find source data in http://ubuntuone.com/4G01ifn7cJ1jMIOKh

Thanks in advance

UPDATE: Thanks to koshke I found the solution. The working code is:

grid.newpage()
pushViewport(viewport(layout = grid.layout(4, 2, heights = unit(c(0.5, 5, 5, 5), "null"))))   
grid.text("MAIN TITLE", vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))
print(tmp, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))         
print(vel, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
print(dir, vp = viewport(layout.pos.row = 3, layout.pos.col = 2))
print(hum, vp = viewport(layout.pos.row = 3, layout.pos.col = 1))
print(pre, vp = viewport(layout.pos.row = 4, layout.pos.col = 1:2))
  • 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-05-27T17:15:11+00:00Added an answer on May 27, 2026 at 5:15 pm

    If I understand correctly what you want to do, probably you can use +opts(title = XXX):

    p1 <- ggplot(mtcars, aes(factor(cyl))) + geom_bar()
    p2 <- ggplot(mtcars, aes(wt, mpg)) + geom_point()
    p3 <- p2 + geom_line()
    
    pushViewport(viewport(layout = grid.layout(2, 2)))  
    print(p1 + opts(title = "bar"), 
      vp = viewport(layout.pos.row = 1, layout.pos.col = 1))     
    print(p2 + opts(title = "point"), 
      vp = viewport(layout.pos.row = 1, layout.pos.col = 2))     
    print(p3 + opts(title = "point and line"), 
      vp = viewport(layout.pos.row = 2, layout.pos.col = 1:2))
    

    enter image description here

    UPDATED

    here is an example:

    pushViewport(viewport(layout = grid.layout(3, 2, heights = unit(c(1, 4, 4), "null"))))
    grid.text("title of this panel", vp = viewport(layout.pos.row = 1, layout.pos.col = 1:2))
    print(p1, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
    print(p2, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
    print(p3, vp = viewport(layout.pos.row = 3, layout.pos.col = 1:2))
    

    what you need to do is:

    1. Make one extra row in grid.layout
    2. Adjust width
    3. Draw textGrob on the extra viewport row.

    enter image description here

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

Sidebar

Related Questions

Ok, so I found a question in this post here: SELECT * FROM help
This question is a little different from the others I've found here. My In
I'm attempting to following the tutorials found here: http://www.ifadey.com/2010/06/crud-using-jquery-and-codeigniter/ My code is updated to
This is a follow up question from my previous one found here I need
From the help for the Overflow Error in VBA, there's the following examples: Dim
With some kindly help from StackOverflow, I've got Unity Framework to create my chained
I managed to get some help from a previous question and I have the
Update: A sample project reproducing this bug can be found here at Microsoft Connect
Following the instruction found here: Insert a datasheet into a form I get an
I am extrapolating from a User model given in the Rails tutorial found here

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.