[英]Change label in ggpairs upper panel
Do you know how to change the labels in an upper panel in ggpairs
( Ggally
package)? 你知道如何在
ggpairs
( Ggally
包)的上面板中更改标签吗? I found how to change size, font but not label. 我发现如何更改大小,字体而不是标签。 Here I want to shorten the label ("set" pour setosa etc...).
在这里,我想缩短标签(“set”pour setosa等...)。 I tried to put that in
labels=c("set", "ver", "vir")
or upper=list(params=list(size=8),labels=c("set", "ver", "vir"))
but it doesn't work. 我试着把它放在
labels=c("set", "ver", "vir")
或upper=list(params=list(size=8),labels=c("set", "ver", "vir"))
但它不起作用。
ggpairs(iris, columns=c(2:4), title="variable analysis", colour="Species",
lower=list(params=list(size=2)), upper=list(params=list(size=8)))
It is a bit ugly, but you could do this (rename the levels in the plot): 它有点难看,但你可以这样做(重命名图中的水平):
library(GGally)
gplt <- ggpairs(iris, columns=c(2:4),
title="variable analysis",
colour="Species",
lower=list(params=list(size=2)),
upper=list(params=list(size=6)))
levels(gplt$data$Species)[levels(gplt$data$Species)=="versicolor"] <- "ver"
levels(gplt$data$Species)[levels(gplt$data$Species)=="virginica"] <- "vir"
levels(gplt$data$Species)[levels(gplt$data$Species)=="setosa"] <- "set"
print(gplt)
Conceptually the same as @Mike's solution, but in one line. 概念上与@Mike的解决方案相同,但在一行中。
levels(iris$Species) <- c("set", "ver", "vir")
ggplairs(<...>)
Here's another, more flexible proposal if you have many levels and do not want to abbreviate them by hand: trim levels to a desired length. 如果您有多个级别并且不想手动缩写它们,则这是另一个更灵活的提议:将级别修剪为所需长度。
levels(iris$Species) <- strtrim(levels(iris$Species), 3)
ggplairs(<...>)
And by the way, the width
parameter is also vectorized: 顺便说一下,
width
参数也是矢量化的:
rm(iris)
strtrim(levels(iris$Species), c(1, 3, 5))
#[1] "s" "ver" "virgi"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.