Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing ggplot2 how can I represent a dot and a line in the legend
    primarykey
    data
    text
    <p>Using ggplot2 I am plotting several functions and a series of points. I cannot figure out how to represent the points on the legend. I realize I need to use an aes() function, but I don't fully understand how to do this. I apologize that the example is so long, but I don't know how else to illustrate it.</p> <pre><code>## add ggplot2 library(ggplot2) # Declare Chart values y_label = expression("y_axis"~~bgroup("(",val / km^{2},")")) x_label = "x_axis" ############################# ## Define functions # Create a list to hold the functions funcs &lt;- list() funcs[] # loop through to define functions for(k in 1:21){ # Make function name funcName &lt;- paste('func', k, sep = '' ) # make function func = paste('function(x){exp(', k, ') * exp(x*0.01)}', sep = '') funcs[[funcName]] = eval(parse(text=func)) } # Specify values yval = c(1:20) xval = c(1:20) # make a dataframe d = data.frame(xval,yval) # Specify Range x_range &lt;- range(1,51) # make plot p &lt;-qplot(data = d, x=xval,y=yval, xlab = x_label, ylab = y_label, xlim = x_range )+ geom_point(colour="green") for(j in 1:length(funcs)){ p &lt;- p + stat_function(aes(y=0),fun = funcs[[j]], colour="blue", alpha=I(1/5)) } # make one function red p &lt;- p + stat_function(fun = funcs[[i]], aes(color="red"), size = 1) + scale_colour_identity("", breaks=c("red", "green","blue"), labels=c("Fitted Values", "Measured values","All values")) # position legend and make remove frame p &lt;- p + opts(legend.position = c(0.85,0.7), legend.background = theme_rect(col = 0)) print(p) </code></pre> <p>Thank you in advance - I have learned I a lot from this community over the last few days.</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.
    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