[英]Suppressing legend
請看下圖。
如何抑制以黃色突出顯示的圖例?
以下是我的代碼。 show.legend = FALSE
不起作用。
plots_yearly_avg_price<-lapply(overall_yearly_average_price,function(category_table){o<-melt(category_table, id = "Year", measure = c("THDT yearly avg price","All national and private label yearly avg price","Private label yearly avg price"));
ggplot(o, aes(Year, value, colour = variable),**show.legend=FALSE**) + geom_line()+
geom_label_repel(aes(label=value))+
labs(title=paste(category_table$Category,"Yearly avg. price",sep=" "),y="Average price")})
您應該添加show.legend = FALSE
各的geom
你不想顯示相應的圖例。 例如,在您的geom_label_repel
中抑制彩色字母(與此功能相關):
ggplot(o, aes(Year, value, colour = variable)) +
geom_line()+
geom_label_repel(aes(label=value), show.legend = FALSE)+
labs(title=paste(category_table$Category,"Yearly avg. price",sep=" "),y="Average price")})
或者,您可以使用theme(legend.position = "none")
來完全抑制您的圖例。
ggplot(o, aes(Year, value, colour = variable)) +
geom_line()+
geom_label_repel(aes(label=value), show.legend = FALSE)+
labs(title=paste(category_table$Category,"Yearly avg. price",sep=" "),y="Average price")})+
theme(legend.position = "none")
它回答你的問題嗎?
plots_yearly_avg_price<-lapply(overall_yearly_average_price,function(category_table){o<-melt(category_table, id = "Year", measure = c("THDT yearly avg price","All national and private label yearly avg price","Private label yearly avg price"));
ggplot(o, aes(Year, value, colour = variable)) + geom_line()+
geom_label_repel(aes(label=value))+
labs(title=paste(category_table$Category,"Yearly avg. price",sep=" "),y="Average price")+guides(colour=FALSE)})
作品。 我在最后添加了“ +guides(colour=FALSE)
”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.