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

  • Home
  • SEARCH
  • 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 9179731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:52:25+00:00 2026-06-17T17:52:25+00:00

Using ggplot2 I want to draw a line that changes colour after a certain

  • 0

Using ggplot2 I want to draw a line that changes colour after a certain date. I expected this to be be simple, but I get a break in the line at the point the colour changes. Initially I thought this was a problem with group (as per this question; this other question also looked relevant but wasn’t quite what I needed). Having messed around with the group aesthetic for 30 minutes I can’t fix it so if anybody can point out the obvious mistake…

screenshot

Code:

require(ggplot2)

set.seed(1111)
mydf <- data.frame(mydate = seq(as.Date('2013-01-01'), by = 'day', length.out = 10),
    y = runif(10, 100, 200))
mydf$cond <- ifelse(mydf$mydate > '2013-01-05', "red", "blue")

ggplot(mydf, aes(x = mydate, y = y, colour = cond)) +
    geom_line() +
    scale_colour_identity(mydf$cond) +
    theme()
  • 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-17T17:52:26+00:00Added an answer on June 17, 2026 at 5:52 pm

    If you set group=1, then 1 will be used as the group value for all data points, and the line will join up.

    ggplot(mydf, aes(x = mydate, y = y, colour = cond, group=1)) +
      geom_line() +
      scale_colour_identity(mydf$cond) +
      theme()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using ggplot2 to plot simple line charts of time series data. One
I am using ggplot2 to plot a figure that contains nine facets. Each facet
I have the following graph that I generated using ggplot2 I had finalPlot as
I want to draw ellipses, hyperbolas in R. How can I do it using
Using ggplot2 , I want to create a histogram where anything above X is
I have created a graph using ggplot2. Now I want to have the legend
I have R code (using ggplot2) that pumps out a bunch of charts to
In ggplot2 I'm attempting a simple thing that I just can't get for some
I'm using ggplot and have two graphs that I want to display on top
I want to position a plotmath symbol (x bar) in a plot using ggplot2.

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.