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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:29:13+00:00 2026-06-10T16:29:13+00:00

There were example code for E on ggplot2 library: theme_set(theme_bw()) dat = data.frame(value =

  • 0

There were example code for E on ggplot2 library:

theme_set(theme_bw())

dat = data.frame(value = rnorm(100,sd=2.5))
dat = within(dat, { 
    value_scaled = scale(value, scale = sd(value))    
obs_idx = 1:length(value)
  })

ggplot(aes(x = obs_idx, y = value_scaled), data = dat) + 
  geom_ribbon(ymin = -1, ymax = 1, alpha = 0.1) +
  geom_line() + geom_point()

There is a question: How I can make in ggplot2 my first 10 lines in red and the rest lines in blue based on example? I tried to use some kind of layer syntax is, but it doesn’t work.

  • 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-10T16:29:14+00:00Added an answer on June 10, 2026 at 4:29 pm

    First, add another column to your data frame dat. It has value 0 for the first 10 rows and 1 for the rest.

    dat$group <- factor(rep.int(c(0, 1), c(10, nrow(dat)-10)))
    

    Generate the plot:

    library(ggplot2)
    
    ggplot(aes(x = obs_idx, y = value_scaled), data = dat) +
    geom_ribbon(ymin = -1, ymax = 1, alpha = 0.1) +
    geom_line(aes(colour = group), show_guide = FALSE) +
    scale_colour_manual(values = c("red", "blue")) +
    geom_point()
    

    The parameter show_guide = FALSE suppresses the legend for the red and blue lines.

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

Sidebar

Related Questions

Example Code: EmigProb<-c(rep(seq(0.1,0.8,length=5),4),rep(seq(0.1,0.8,length=5),4)) RemainEmigProb<-c(rep(0.2,5),rep(0.4,5),rep(0.6,5),rep(0.8,5),rep(0.2,5),rep(0.4,5),rep(0.6,5),rep(0.8,5)) Value<-rnorm(40,5,3) Parameter<-c(rep(Survival,20),rep(Resight,20)) fakedata<-data.frame(EmigProb=EmigProb,RemainEmigProb=RemainEmigProb,Value=Value,Parameter=Parameter) q <-ggplot(fakedata,aes(EmigProb,Value,shape=factor(RemainEmigProb),colour=factor(Parameter),linetype=factor(RemainEmigProb)))+scale_colour_discrete(Parameter)+scale_linetype_discrete(Remain Emigrant Probability)+scale_shape_manual(Remain Emigrant Probability,values=c(0,5,6,15)) q
is there any example code of setting up tinymce within your web application using
Is there any code example teaching how to zoom in and out in a
In the pickle module documentation there is a snippet of example code: reader =
I just started using Qt and noticed that in each example code folder there
I'm reading the book 'Beginning F#', There's a short list for example code, to
There is an excellent code example on how to make nice jQuery Twitter style
Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
What is the best practice of placing example usage in code documentation? Is there
For example we have this line chart at Google Code API there is 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.