Do you know how to change the labels in an upper panel in ggpairs
(Ggally
package)? I found how to change size, font but not label. Here I want to shorten the label ("set" pour setosa etc...). 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.
ggpairs(iris, columns=c(2:4), title="variable analysis", colour="Species",
lower=list(params=list(size=2)), upper=list(params=list(size=8)))
Conceptually the same as @Mike's solution, but in one line.
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:
rm(iris)
strtrim(levels(iris$Species), c(1, 3, 5))
#[1] "s" "ver" "virgi"
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With