ggplot2:更改图例符号 [英] ggplot2: Change legend symbol
本文介绍了ggplot2:更改图例符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我绘制了几行文字,我想知道如何将图例中的符号从细线变为完整的块。
我试图从
转换为
(使用geom_line而不是geom_bar)
<您可以使用函数 guides()
,然后使用参数 override.aes =>解析方案
set line size =
(width)为一些大的值。在内为
设置 fill = NA
> theme()。
df <-data.frame(x = rep(1:5每个= 3),y = 1:15,group = rep(c(A,B,C),each = 5))
ggplot(df,aes(x,y, color = group,fill = group))+ geom_line()+
guides(color = guide_legend(override.aes = list(size = 10)))+
theme(legend.key = element_rect(fill = NA))
I have plotted several lines and I am wondering how to change the symbol in the legend to go from the thin line to a full block.
I am trying to go from
to
(while using geom_line and not geom_bar)
解决方案
You can use function guides()
and then with argument override.aes=
set line size=
(width) to some large value. To remove the grey area around the legend keys set fill=NA
for legend.key=
inside theme()
.
df<-data.frame(x=rep(1:5,each=3),y=1:15,group=rep(c("A","B","C"),each=5))
ggplot(df,aes(x,y,color=group,fill=group))+geom_line()+
guides(colour = guide_legend(override.aes = list(size = 10)))+
theme(legend.key=element_rect(fill=NA))
这篇关于ggplot2:更改图例符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文