简体   繁体   English

在ggbiplot中更改图例标题

[英]change legend title in ggbiplot

I'm having trouble manipulating ggbiplot such that I can specify what the title of the legend is. 我在操作ggbiplot遇到麻烦,无法指定图例的标题。 Using the package data: 使用包数据:

library(ggbiplot)
data(wine)
wine.pca <- prcomp(wine, scale. = TRUE)
p <- ggbiplot(wine.pca, obs.scale = 1, var.scale = 1, groups = wine.class, 
              ellipse =  TRUE, circle = TRUE)

I've tried the following 我尝试了以下

p + scale_fill_discrete(name="New Title")
p + guides(fill=guide_legend(title="New Legend Title"))

but I have no luck with either. 但我也没有运气。 I was wondering if somebody was familiar with this package and was able to advise as to how to change the legend title. 我想知道是否有人熟悉这个软件包,并且能够建议如何更改图例标题。

As you are plotting points and their aesthetics is color and accordingly you should use color= instead of fill= 在绘制点时,它们的美感是颜色,因此应使用color=而不是fill=

p+guides(color=guide_legend("Legend title"))

or 要么

p + labs(color="Legend title")

同时,它与scale_color_discrete(name = 'Legend title')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM