Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

label X axis on ggscatter

I have a dataframe with 2 columns to do a correlation. The data is of integer number from 1 to 10.
However, when I use the ggscatter, the axis (X and Y) uses a scale of 0, 2.5, 5, 7.5 and 10. I want to change it. It doesn’t need to be all the number, however it never will be 2.5 or 7.5.

How can I make this?

Here are my code (with a sample to make this example).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

X_AXIS = sample(c(1:10),size = 100, replace = TRUE)
Y_AXIS = sample(c(1:10),size = 100, replace = TRUE)

novaTabela = data.frame(X_AXIS, Y_AXIS)
ggscatter(novaTabela, x = "X_AXIS", y = "Y_AXIS", 
          add = "reg.line", 
          cor.coef = TRUE, cor.method = "pearson")

>Solution :

just by adding the labels and breaks to the scale using scale_x_continuous (or scale_y_continuous) as we do in ggplot. Also, note that, whatever change you make to the label, define those for breaks argument too.

library(ggpubr)

X_AXIS = sample(c(1:10),size = 100, replace = TRUE)
Y_AXIS = sample(c(1:10),size = 100, replace = TRUE)

novaTabela = data.frame(X_AXIS, Y_AXIS)

p <- ggscatter(novaTabela, x = "X_AXIS", y = "Y_AXIS", 
          add = "reg.line", 
          cor.coef = TRUE, cor.method = "pearson")

p + scale_x_continuous(labels = seq(1, 10, 3), breaks = seq(1, 10, 3))

ggpubr plot with manually defined scale label

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading