Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在GGR中的绘图中添加图例_R_Ggplot2_Legend - Fatal编程技术网

如何在GGR中的绘图中添加图例

如何在GGR中的绘图中添加图例,r,ggplot2,legend,R,Ggplot2,Legend,我希望在绘图的右上角包含一个图例,指示绘图的参数值 ggplot() + geom_line(data=data1, aes(x=x, y=y1), color='green', linetype = "twodash", size=0.5) + geom_line(data=data2, aes(x=x, y=y2), color='red', linetype="longdash", size=0.5) + geom_line(data=data3, aes(x=x, y=y

我希望在绘图的右上角包含一个图例,指示绘图的参数值

ggplot() + 
  geom_line(data=data1, aes(x=x, y=y1), color='green', linetype = "twodash", size=0.5) + 
  geom_line(data=data2, aes(x=x, y=y2), color='red', linetype="longdash", size=0.5) +
  geom_line(data=data3, aes(x=x, y=y3), color='blue') +
  theme_classic() +
  labs(x='input, x',
       y='output, f(x)')

有人能告诉我这是怎么做到的吗。谢谢。

我认为这是“如何处理ggplot”的一个很好的来源

从那里

# Position legend in graph, where x,y is 0,0 (bottom left) to 1,1 (top right)
bp + theme(legend.position=c(1, 1))
应该/可以这样做吗?

请参见,但更好的策略是将数据合并到一个对象中并绘制该对象