I have two questions about plotting with ggpairs
in r
:
(1) I have some unavoidably long variable names that are not shown in full in the default output of ggpairs. How can I adjust ggpairs so that the whole name is visible (e.g. can labels be split over multiple lines, or displayed at 45 degrees, etc.)?
and (2), How do I set a custom range for axis limits for individual variables?
For example, the following code gives us the plot below:
library(GGally)
set.seed(99)
really_long_variable_name_1 <- round(runif(50, 0, 1), 2)
really_long_variable_name_2 <- round(runif(50, 0, 0.8), 2)
really_long_variable_name_3 <- round(runif(50, 0, 0.6), 2)
really_long_variable_name_4 <- round(runif(50, 0, 100), 2)
df <- data.frame(really_long_variable_name_1,
really_long_variable_name_2,
really_long_variable_name_3,
really_long_variable_name_4)
ggpairs(df)
(1) How do I adjust the plot so that full variable names are visible (in this case, the labels on the Y axis)?
and (2) How would I set the axes limits at 0 to 1 for the first three variables, and 0 to 100 for the fourth?
I can set all axes limits to the same values using a function like the one below:
custom_range <- function(data, mapping, ...) {
ggplot(data = data, mapping = mapping, ...) +
geom_point(...) +
scale_x_continuous(limits = c(0, 1)) +
scale_y_continuous(limits = c(0, 1))
}
ggpairs(df,
lower = list(continuous = custom_range))
but how would I set axis limits for the fourth variable, really_long_variable_name_4
, so that X ranges from 0 to 100?
Many thanks.