0

I am trying to plot 2 lines with errorbars over 3 points. Points are marked with shape and fill. Basically, the graph should look like that one.

Without changing the labels of the legend, I succeeded and graph is almost perfect. However, I do want to change legend labels and when I try this, I can't make it work.

After setting style of points manually (fill and shape), I use scale_shape_discrete to set the labels, but get following warning: "Scale for 'shape' is already present. Adding another scale for 'shape', which will replace the existing scale."

The product then has two legends (once the old and once the new one), but also the elements in the plot are reset (no fill information any more).

I followed the instructions on this tutorial to avoid having multiple legends. However, the plots are still missing fill information.

Any suggestions what could be wrong here?

Btw. Here my code:

# plot
p <- ggplot(gBasicCond, aes(x=color_switch, y=RT, fill=exp,shape=exp))+ 
geom_line(aes(group=exp)) + geom_point(aes(group=exp), size =4) + 
geom_errorbar(limits,width = 0.1)+
scale_shape_manual(values=c(21,24)) + 
scale_fill_manual(values=c("white","black")) + 
geom_vline(xintercept = 2.5,linetype = "dotted")+ ylim(200,350) + 
xlab('Target Selection') +  ylab('Fixation duration (in ms)') + 
scale_x_discrete( labels=c("Repetition","Switch","Single-target")) + 
theme_bw() + 
#scale_fill_discrete(name = 'Experiment', labels=c("Full fixation ", "Outline fixation")) + 
scale_shape_discrete(name = 'Experiment',labels=c("Full fixation ", "Outline fixation")) + 

Thanks,

E

userE
  • 249
  • 3
  • 12
  • Can you add toy data for `gBasicCond` that would make it possible for others to run your code? – Curt F. Jul 27 '15 at 15:36
  • 1
    Both `scale_shape_manual` and `scale_fill_manual` have `name` and `labels` argument. Thus, no need for `scale_fill_discrete` or `scale_shape_discrete` (which are causing the warning). Please re-read the help text. – Henrik Jul 27 '15 at 15:49
  • @Henrik, thank you. That solved it. For some reason I only thought of combining these two commands in the `scale_xxx_discrete` functions, but not in`scale_xxx_manual`s. Consider this question solved (can't find where to mark it as such) – userE Jul 28 '15 at 07:03
  • 1
    Great! For next time, learn how to produce a _minimal_, self contained example: see [**here**](http://stackoverflow.com/help/mcve), and [**here**](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). – Henrik Jul 28 '15 at 07:07

0 Answers0