1 修改图例标注 标签
内容修改、序列修改
标注排序修改breaks,breaks——labels,
p + scale_colour_discrete(
1. 修改图例标注/标签
内容修改、序列修改
##标注排序修改breaks,breaks——labels, p + scale_colour_discrete(#values=c("#CC0000", "#006600", "#669999", # "#00CCCC", "#660099"),或者color/fill/colour,discrete/hue, name="Experimental", breaks = c("6","4","8"), labels = c("B","A","C"))
2. 修改图例标题名称
##第一种color/fill/colour,discrete/hue p + scale_colour_discrete( name="Experimental", breaks = c("6","4","8"), labels = c("B","A","C")) ##第二种修改图例标题 p + labs(colour = "name1", shape = "name2")
3. 隐藏/删除图例标题 标题修改、删除
#第一种, #Remove title for fill legend p + guides(colour=guide_legend(title=NULL)) #注意colour/fill/color/shape转换 #第二种,所有的表题全部移除 # Remove title for all legends p + theme(legend.title=element_blank())
4.图例位置
#1: around the plot "none", "left", "right", "bottom", "top" basic + theme(legend.position = "bottom") #2:inside the plot basic + theme( legend.position = c(.95, .95),#plot内位置 legend.justification = c("right", "top"),#固定右上角 legend.background = element_blank(),#图例背景色 legend.key = element_blank(),#图标背景色element_rect(colour="black") legend.box.background = element_rect(fill=NA,color = "black",linetype = 1) #图例外框和背景色默认填充白色(删除fill=NA) #legend.box.just = "right", #legend.margin = margin(6, 6, 6, 6)#边框大小调整 )
图片呈现是的3
5. 删除图例
#删除其中一个图例 guides(shape=FALSE) #shape/color/colour/fill #全部删除图例 theme(legend.position = "none")
引用
- R语言之可视化①⑨子ggplot2中的图例修改
- ggplot2-设置图例(legend)
总结
到此这篇关于R语言ggplot2图例标签、标题、顺序修改和删除的文章就介绍到这了,更多相关R语言ggplot2图例设置内容请搜索好代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好代码网!