How to Easily Set Axis Ticks Number for Numeric Variables

plot of chunk set-axis-ticks-number


How to Easily Set Axis Ticks Number for Numeric Variables

library(ggpubr)

# Create a basic plot
p <- ggscatter(mtcars, x = "wt", y = "mpg")
p

plot of chunk set-axis-ticks-number

# Increase the number of ticks
p +
 scale_x_continuous(breaks = get_breaks(n = 10)) +
 scale_y_continuous(breaks = get_breaks(n = 10))

plot of chunk set-axis-ticks-number

# Set ticks according to a specific step, starting from 0
p + scale_x_continuous(
  breaks = get_breaks(by = 1.5, from = 0),
  limits =  c(0, 6)
) +
 scale_y_continuous(
  breaks = get_breaks(by = 10, from = 0),
  limits = c(0, 40)
  )

plot of chunk set-axis-ticks-number

Version: Français





No Comments

Give a comment

Want to post an issue with R? If yes, please make sure you have read this: How to Include Reproducible R Script Examples in Datanovia Comments