ggpairs: adjusting axis labels to show minimum and maximum only
Asked Answered
I

0

2

I want to show just the minimum and maximum values for all the axes of a ggpairs {GGally} plot. Find below a reproducible example

df=as.data.frame(matrix(1:1000,nrow = 100))
ggpairs(df)

enter image description here

I know I can do it individually by using breaks, but I don't know how can I apply this in ggpairs. Can somebody help me?

Isodimorphism answered 18/8, 2017 at 20:5 Comment(2)
one way is to define your own function.... my_fn <- function(data, mapping, ...){ ggplot(data = data, mapping = mapping, ...) + ; geom_point(...) + ; scale_y_continuous(breaks=round(range(data[,as.character(mapping$y)]))) +; scale_x_continuous(breaks=round(range(data[,as.character(mapping$x)]))) } . Then plot ggpairs(df, lower=list(continuous=my_fn)) . You can tweak the breaks to make more pretty values, change the density plot similarilty etc etcMicroprint
It works. Thanks. If you post this as an answer I will accept it. I guess I have to do the same for diagonal plots to adjust the axes labels of top-left and bottom-right density plots as well?Isodimorphism

© 2022 - 2024 — McMap. All rights reserved.