R语言中画图时我们常常要设定标题,如果图片标题是固定则很容易操作,下面这篇文章主要给大家介绍了关于R语言ggplot2图例标签、标题、顺序修改和删除操作的相关资料,需要的朋友可以参考下
##标注排序修改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. 删除图例