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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:44:01+00:00 2026-05-16T05:44:01+00:00

I am using ggplot2 (respectively qplot) to generate a report with Sweave. Now I

  • 0

I am using ggplot2 (respectively qplot) to generate a report with Sweave. Now I need some help with the adjustment of the size of the plot. I use the following Sweave code to include it.

\begin{figure}[htbp]
\begin{center}
<<fig=true,echo=false>>=
print(mygraph)
@
\caption{MyCaption}
\end{center}
\end{figure}

If I add a width argument (like shown below) to plot is squeezed down, but not really scaled down.

<<fig=true,echo=false,width=3>>=

If I use ggsave() instead, I could use a scale argument and influence the size of the resulting .pdf file. Is there a way to influence the dimensions of the plot without saving it (since the .pdf is generated by Sweave anyway) ? Is there anything I need to add to my qplot code?

mygraph=qplot(date,value,data=graph1,geom="line",colour=variable,xlab="",ylab="")
+ scale_y_continuous(limits = c(-0.3,0.3))

Thx for any suggestions in advance!

  • 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-16T05:44:02+00:00Added an answer on May 16, 2026 at 5:44 am

    Instead of doing this within ggplot2, add the following LaTeX code before the code chunk where you print the graph.

    \SweaveOpts{width=x, height=y}
    

    x and y are height and width in inches.

    If there is a particular aspect ratio you would like your plot to be, you can set this in ggplot2 with opts(). Unless I have some other reason, I usually try to keep my plots scaled to the golden ratio, per Tufte’s suggestions. Usually I have

    ...
    SweaveOpts{width=8, height=5}
    ...
    <<label = "makeplot", echo = F>>=
      p <- ggplot(mpg, aes(displ, hwy)) + 
        geom_point()+
        opts(aspect.ratio = 2/(1+sqrt(5)) )
    @
    ...
    \begin{figure}[htbp]
    \begin{center}
    <<fig=true,echo=false>>=
      print(p)
    @
    \caption{MyCaption}
    \end{center}
    \end{figure}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I started to use ggplot in order to generate some graphs. I am using
I'm trying to make a presentation on ggplot2 graphics using beamer + sweave. Some
I'm using ggplot2 and attempting to create an empty plot with some basic dimensions,
Using ggplot2 generate a plot which shows the following data. df=data.frame(score=c(4,2,3,5,7,6,5,6,4,2,3,5,4,8), age=c(18,18,23,50,19,39,19,23,22,22,40,35,22,16)) str(df) df
I'm trying to plot timeseries data using ggplot2. Specifically, I'm trying to generate a
I'm using ggplot2 to make some bullseye charts in R. They look delightful, and
I am using ggplot2 to plot a figure that contains nine facets. Each facet
I am trying to produce some example graphics using ggplot2, and one of the
I'm trying to plot heatmap in ggplot2 using csv data following casbon's solution in
I am using ggplot2 to plot a pointrange() plot, and both the x and

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.