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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:33:16+00:00 2026-06-09T20:33:16+00:00

I have a data frame, where I am talking about different flows of water

  • 0

I have a data frame, where I am talking about different flows of water at a dam (water units are kcfs—1000 cubic feet per second—if anyone is interested)

Call it df4plot

    date         kcfs    Flowtype
    10/1/2010        50     Power
    10/1/2010        10     Spill_Overgen
    10/1/2010         8         Spill_Force
    10/2/2010        52     Power
    10/2/2010         7     Spill_Overgen
    10/2/2010        10     Spill_Force     

(there are 3×365 rows in the data frame)

So what I want to do is make an aggregated area graph that shows each of these flows

p <- ggplot(data = df4plot, aes(date,kcfs)) +
geom_area(aes(colour = Flowtype, fill=Flowtype), position = “stack”) 

I want to control the colors used, so I added

plot_colors_aggregate <- c("forestgreen","lightsalmon","dodgerblue")
p <- p +
scale_color_manual(values = plot_colors_aggregate) +
scale_fill_manual(values = plot_colors_aggregate)

Now I want to add a dashed line, showing the maximum turbine capacity—the flow limits for power generation—that vary by month. I have a separate dataframe for this (365 rows long), df4FGline

    Date    FGlimit
    10/1/2010   52
    10/2/2010   52
     …
    11/1/2010   60
    11/2/2010   60
    ...
    Etc

So now I have

p <- p + 
geom_line(data = df4FGline, aes(x=date,y=FGlimit), colour = “darkblue”, linetype = “dashed”)

p

The legend is currently just the three blocks for the three types of Flowtype. I’d like to add the dashed line for the flow gate limits to the bottom, but I can’t get it to show up there.

It is probably related to my incomplete understanding of aes (help(aes) is AMAZINGLY unhelpful).

I’ve tried something similar to this and something similar to this, but since I’m only trying to add 1 line to a pre-existing legend, maybe?, this is not working for me.

I tried adding “legend = TRUE” inside the parentheses for the geom_line, but it put a dashed line inside each color box in the legend, AND created a 4th entry for the legend, but offset from the rest of the legend (below and to the right)… ARG!

I swear I have the book on order… any help you can share so that I understand this aesthetic thing and how it relates to the legend a little better, I’d be extremely grateful.

edited for typo

  • 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-09T20:33:17+00:00Added an answer on June 9, 2026 at 8:33 pm

    This should help:

    df <- data.frame(x = 1:10,y = 1:10)
    ggplot(df,aes(x = x,y = y)) + 
       geom_line(aes(linetype = "dashed")) + 
       scale_linetype_manual(name = "Linetype",values = "dashed")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data frame that's about ts1[100, 2000] in dimension as follows: >
I have a big data frame taking about 900MB ram. Then I tried to
If I have data like this DF <- data.frame( date = seq(Sys.Date()-1000, len=1000, by=1
I have data frame with some numerical variables and some categorical factor variables. The
I have a data frame with start dates and end dates, along with the
I have a data frame like below (20,000 rows by 49 cols). Each row
I have a data frame with two qualitative variables (Q1, Q2) which are both
I have a data frame that is some 35,000 rows, by 7 columns. it
I have a data frame consisting of results from multiple runs of an experiment,
I have a data frame of daily data: df with four columns: Date, 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.