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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:18:27+00:00 2026-06-09T00:18:27+00:00

I am creating an R script to produce a chart consisting of multiple lines.

  • 0

I am creating an R script to produce a chart consisting of multiple lines. I have produced a basic chart, and have managed to smooth each of the plotted lines. However, I want to beautify the chart by doing the following:

  1. Currently, each line is plotted as a smoothed line. I want to plot the smoothed line using some other line type e.g. dash-dot, dash-dash-dot etc.

  2. I want to add a legend to the chart, and display a line (same color as the line it represents in the main chart), in the legend.

  3. Specify font size for the main chart title, x and y

Here is what I have so far:

dat  <- read.csv(filename, sep=',')

xvals <- dat$xvals
y1  <- dat$y1
y2  <- dat$y2
y3  <- dat$y3
y4  <- dat$y4
y5  <- dat$y5
y6  <- dat$y6

lo1 <- loess(y1~xvals)
lo2 <- loess(y2~xvals)
lo3 <- loess(y3~xvals)
lo4 <- loess(y4~xvals)
lo5 <- loess(y5~xvals)
lo6 <- loess(y6~xvals)

plot(xvals,y1, xlab='X label', ylab='Y label', type='n')
xl <- seq(min(xvals),max(xvals), (max(xvals) - min(xvals))/1000)
lines(xl, predict(lo1,xl), col='gray', lwd=1)
lines(xl, predict(lo2,xl), col='pink', lwd=1)
lines(xl, predict(lo3,xl), col='red', lwd=1)
lines(xl, predict(lo4,xl), col='cyan', lwd=1)
lines(xl, predict(lo5,xl), col='black', lwd=1)
lines(xl, predict(lo6,xl), col='green', lwd=1)

legend("topright", "(x,y)", pch=1, lty=c(1,1), # gives the legend appropriate symbols (lines)
       , lwd=c(1,1),col=c("blue","red"), inset = .02)

How do I modify the code above to implement the requirements 1 – 3 above?

As an aside, I am aware of ggplot. I think I’ll stick with plot() – I find ggplot far too cryptic, puzzling and infuriating.

  • 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-09T00:18:29+00:00Added an answer on June 9, 2026 at 12:18 am

    Since I had started work on an answer already:

    Make up some data:

    dat <- data.frame(xvals=1:100,
                      y=matrix(rnorm(600),ncol=6))
    

    Create formulae, apply loess and predict, collapse the results into a matrix:

    formulae <- lapply(names(dat)[-1],
                       function(yvar) as.formula(paste(yvar,"xvals",sep="~")))
    loessfits <- lapply(formulae,loess,data=dat)
    
    xl <- with(dat,seq(min(xvals),max(xvals), length.out=1000))
    pvals <- do.call(cbind,lapply(loessfits,predict,newdata=data.frame(xvals=xl)))
    

    Set parameters (it’s always worth going back and spending some more time reading ?par):

    ## set box type (open), horizontal tick labels, axis label and title size
    par(bty="l",las=1,cex.main=2,cex.lab=2)
    

    Set up colo(u)rs and line types:

    cvec <- c("gray","pink","red","cyan","black","green")
    lvec <- 1:6
    

    Create the plot:

    matplot(xl,pvals,type="l",col=cvec,lty=lvec,
            xlab='X label', ylab='Y label')    
    legend("topright", paste0("L",1:6), pch=1, lty=lvec,col=cvec, inset = .02)
    

    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 have simple table creating script in Postgres 9.1. I need it to create
Am creating a script using JQuery on an ASP.NET page. Have a JSON string
I am creating a basic msi project using installsheild 2012 premier. I have two
I'm creating a script to only upload zip files and I have the following
I have to related tables like in the example script below: -- Creating table
I am creating a simple comparison script and I have some questions for the
I'm creating a script that can be deployed to multiple administrators who would be
I have a script that is creating a lot of configurable products and their
Well I am creating a script to automatically generate documentation for my projects with
I am creating a script that I can run and it will simply ask

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.