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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:54:29+00:00 2026-05-27T07:54:29+00:00

I am still learning Sweave and R . I have below a sample code

  • 0

I am still learning Sweave and R. I have below a sample code that reads in a data file and plots it. I am choosing the postscript option as I like ending up with an EPS file. There are a number of things that I would like to improve with the plot. Here is my code with my own comments for my own learning:

\documentclass[a4paper,12pt]{article}
\usepackage{Sweave}  %%%%%%
\SweaveOpts{eps=TRUE}

\begin{document}

<<echo=FALSE, results=hide>>=
test.frame<-data.frame(ratio= c(0.0, 144.321, 159.407, 178.413, 202.557), value= c(0, 0.84, 0.8925, 0.945, 0.9975))
@


<<echo=FALSE,results=hide,eval=TRUE>>=
postscript('doudou.eps',
               width=7, height=6,
               colormodel="cmyk",
               family = "ComputerModern",
               horizontal = FALSE,
               onefile=FALSE,
               paper = "special",
               encoding = "TeXtext.enc",
               pagecentre=FALSE)

with(test.frame,plot(ratio, value, ylab= "Hello",
                                   xlab="Wonderful",
                                   type="o",        # line and markers
                                   bty="o",         # box around graph
                                   lty="solid",     # solid line or put 1
                                   lwd=3,            # line width
                                   pch=1,            # or enclose symbol in quotes
                                   cex=3,             # size of markers
                                   cex.lab=2,        # label size
                                   cex.axis=1.5,    # axis annot size problem if big
                                   cex.main=2,          # main title size
                                   xaxp=c(0, 200, 4),  #c(x1, x2, n)
                                   col=2,              # plotting color
                                   xlim=c(0,200),
                                   yaxt = "n",         #suppresses axis
                                   main=" My curve"))

axis(2,seq(0,1, by=0.5), las=2,cex=3,cex.lab=2,cex.axis=1.5,cex.main=2)

dev.off()
@

\begin{figure}[htbp]
\begin{center}
\includegraphics[width=0.8\textwidth]{doudou.eps}
\end{center}
\end{figure}


\end{document}

Some things that I would like to know more about an improve:

  1. I have a boxed frame around the plot. How to control its line width?

  2. I am using cex.axis=1.5for the axis annotation size. if I change it to say cex.axis=3 then the values on the x-axis get big and they overlap with the tickmarks. Is there a way to then place the x-axis values a bit lower further away from the plot?

  3. The y-label Hello is truncated at the top of the H letter in the plot. How to fix this?

  4. How to move either the x-label Wonderful or y-label Hello further away from the plot?

  5. If we look at the plotted curve, the axes do not start at (0,0) though the initial values are (0,0) for the data set. How to control the axes so that they start at (0,0)?

Thanks a lot…

  • 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-27T07:54:30+00:00Added an answer on May 27, 2026 at 7:54 am

    “I have a boxed frame around the plot. How to control its line width?”

     box(lwd=3)
    

    “I am using cex.axis=1.5 for the axis annotation size. If I change it to say cex.axis=3 , then the values on the x-axis get big and they overlap with the tickmarks. Is there a way to then place the x-axis values a bit lower further away from the plot?”

    par(mgp=c(3,1.5,0) )  # second element is number of lines below the box for the labels
    

    “The y-label Hello is truncated at the top of the H letter in the plot. How to fix this?”

    # use par() to increase left margins
    

    “How to move either the x-label Wonderful or y-label Hello further away from the plot?”

    par( mgp=c(4,1.5,0) ) # First element in mgp vector
    

    “If we look at the plotted curve, the axes do not start at (0,0) though the initial values are (0,0) for the data set. How to control the axes so that they start at (0,0)?”

     ..., xaxs="i", yaxs="i", ... # can be done in `par` or in the plot call
    

    So the R code for the figure is below:
    So the R code for the figure is below:

    postscript('doudou.eps',
                   width=7, height=6,
                   colormodel="cmyk",
                   family = "ComputerModern",
                   horizontal = FALSE,
                   onefile=FALSE,
                   paper = "special",
                   encoding = "TeXtext.enc",
                   pagecentre=FALSE)
    par( mgp=c(4,1.5,0), mai=c(1.5, 1.5, 1.5, .75) )  # using inches as the spacing unit
    with(test.frame, plot(ratio, value, ylab= "Hello", 
                                xaxs="i", yaxs="i",
                                       xlab="Wonderful",
                                       type="o",        # line and markers
                                       bty="o",         # box around graph
                                       lty="solid",     # solid line or put 1
                                       lwd=3,            # line width
                                       pch=1,            # or enclose symbol in quotes
                                       cex=3,             # size of markers
                                       cex.lab=2,        # label size
                                       cex.axis=3,    # axis annot size problem if big
                                       cex.main=2,          # main title size
                                       xaxp=c(0, 200, 4),  #c(x1, x2, n)
                                       col=2,              # plotting color
                                       xlim=c(0,200),
                                       yaxt = "n",         #suppresses axis
                                       main=" My curve"))
    
    axis(2,seq(0,1, by=0.5), las=2,cex=3,cex.lab=2,cex.axis=1.4, cex.main=2)
    box(lwd=3)
    dev.off()
    

    Not pretty, but it does illustrate the control functions. Basically you need to spend more time on the help(par) page.

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

Sidebar

Related Questions

I am still learning Perl scripting and need help in doing below task. Sample
Ok still learning here. If I have one form calling another form like below
I'm still learning Perl and CLASS::DBI. I have a script that does a bunch
I'm still learning JavaScript,reading books,utilizing FireBug,experimenting. I'm amazed and stuck on thing below. Have
I'm still learning Grails and seem to have hit a stumbling block. Here are
I'm still learning ASP.NET and I often see code like this throughout parts of
I'm still learning Rhino mocks and have a question about it. For example -
I am still learning MySQL queries and am stuck with this one. I have
Still learning jquery here and I've tried to setup a set of divs that
I'm still learning about jQuery, but I have not been able to find a

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.