[英]How to remove borders from the legend without removing borders from the bar plot in ggplot2
[英]ggplot2 moving legend in to plot area without borders around key
嗨,我正在嘗試將我的圖例區域添加到我的繪圖區域,而我的密鑰周圍沒有白色邊框。 到目前為止,我有這個:
繪圖區域中的圖例但存在白色邊框:
我想要的傳奇風格:
ggplot(data=Pig, aes(x=breed, y= p1_plus_p3_fat_depth_mm, color=sex))+
geom_boxplot()+
theme(legend.title=element_blank()) +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank())+
xlab("Pig Breed") +
ylab("The P1 and P3 Fat Depth in mm")+
scale_colour_discrete(name ="Sex",breaks=c("B", "S"),labels=c("Boar", "Sow"))+
theme(legend.justification = c(1, 1), legend.position = c(1, 1))+
theme(legend.background = element_rect(fill="transparent"))
您將需要使用legend.key = element_blank()
刪除箱線圖圖標周圍的背景和邊框。
ggplot(data=iris[c("Species", "Sepal.Length")], aes(x=Species, y= Sepal.Length, color=Species))+
geom_boxplot()+
theme(legend.title=element_blank()) +
theme(panel.grid.major = element_blank()) +
theme(panel.grid.minor = element_blank())+
theme(legend.justification = c(1, 1), legend.position = c(1, 1))+
theme(legend.background = element_blank(),
legend.key = element_blank())
我更喜歡使用element_blank()
刪除主題元素,而不是將其設置為透明並將其留在那里。 我發現根據圖形設備的不同,透明可以有不同的解釋。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.