ggplot2将图例移至绘图区域,按键周围无边框

时间:2019-02-25 12:34:17

标签: r ggplot2

您好,我想将图例区域添加到我的绘图区域,而密钥周围没有白色边框。到目前为止,我有这个:

传说中的情节,但有白色边框:

legend1

我想要的传奇风格:

legend2

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"))

1 个答案:

答案 0 :(得分:1)

您将需要使用showEvents(events: any) {debugger let calendarOptions: Object; let newEvents = []; this.eventSource.map((event) => { event.title = event.name; event.start = event.startTime; event.end = event.endTime; event.status = event.eventStatus; event.allDay = event.isallDay; event.rrule = event.recurrencePattern; newEvents.push(event); }); newEvents.forEach(element => { if(element.recurrencePattern === "RRULE:FREQ=MONTHLY;") { element.dom = [1]; newEvents.push(element); } }); calendarOptions = { header: { left: 'prev,next, today', center: 'title', right: 'month,agendaWeek,agendaDay,listMonth' }, events : newEvents }; 在框线图图标周围放置背景和边框。

legend.key = element_blank()

enter image description here

我更喜欢使用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()) 来删除主题元素,而不是将其设置为透明并保留在那里。我发现根据图形设备的不同,透明的解释也可能有所不同。