Note that there are some explanatory texts on larger screens.

plurals
  1. POadding a key for geom_line to legend from geom_area
    primarykey
    data
    text
    <p>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)</p> <p>Call it df4plot</p> <pre><code> 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 </code></pre> <p>(there are 3x365 rows in the data frame)</p> <p>So what I want to do is make an aggregated area graph that shows each of these flows</p> <pre><code>p &lt;- ggplot(data = df4plot, aes(date,kcfs)) + geom_area(aes(colour = Flowtype, fill=Flowtype), position = “stack”) </code></pre> <p>I want to control the colors used, so I added </p> <pre><code>plot_colors_aggregate &lt;- c("forestgreen","lightsalmon","dodgerblue") p &lt;- p + scale_color_manual(values = plot_colors_aggregate) + scale_fill_manual(values = plot_colors_aggregate) </code></pre> <p>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</p> <pre><code> Date FGlimit 10/1/2010 52 10/2/2010 52 … 11/1/2010 60 11/2/2010 60 ... Etc </code></pre> <p>So now I have </p> <pre><code>p &lt;- p + geom_line(data = df4FGline, aes(x=date,y=FGlimit), colour = “darkblue”, linetype = “dashed”) p </code></pre> <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.</p> <p>It is probably related to my incomplete understanding of aes (help(aes) is AMAZINGLY unhelpful). </p> <p>I’ve tried something similar to <a href="https://stackoverflow.com/questions/9915824/how-can-i-make-a-legend-in-ggplot2-with-one-point-entry-and-one-line-entry">this</a> and something similar to <a href="https://stackoverflow.com/questions/5027016/missing-legend-with-ggplot2-and-geom-line?rq=1">this</a>, but since I’m only trying to add 1 line to a pre-existing legend, maybe?, this is not working for me.</p> <p>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!</p> <p>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.</p> <p><em>edited for typo</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload