首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ggbiplot -更改标签的颜色

ggbiplot -更改标签的颜色
EN

Stack Overflow用户
提问于 2017-08-22 21:15:35
回答 1查看 1.8K关注 0票数 3

默认情况下,ggbiplot函数会给出一个图形,其中负载为红色箭头,单位标签为黑色:

代码语言:javascript
复制
library(ggbiplot)
data("USArrests")
us <- princomp(USArrests)
ggbiplot(us, labels = rownames(us$scores))

是该代码的结果

如何更改这些标签的颜色,以及它们的大小或字体?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-23 07:03:50

代码语言:javascript
复制
library(ggbiplot)
library(grid)
data("USArrests")
us <- princomp(USArrests)

# Cut the third score into 4 intervals using quantiles
cols <- cut(us$scores[,3], quantile(us$scores[,3], probs=seq(0,1,0.25)), include.lowest=T)

# Change label colors using the "group" option
# Change label font size using the "label.size" option
p <- ggbiplot(us, labels = rownames(us$scores), groups=cols, labels.size=4)

# Change label font family 
g <- ggplotGrob(p)
g$grobs[[6]]$children[[4]]$gp$fontfamily <- "mono"
grid.draw(g)

要整体更改标签颜色,请执行以下操作:

代码语言:javascript
复制
p <- ggbiplot(us, labels = rownames(us$scores), groups=1, labels.size=4) +
     theme(legend.position = "none")

# Change label colors 
g <- ggplotGrob(p)
g$grobs[[6]]$children[[4]]$gp$col <- "#FF9900"
grid.draw(g)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45818712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档