Reputation: 6930
Here is sample code:
library("ggpubr")
# Load data
data("ToothGrowth")
df <- ToothGrowth
# Basic plot
ggboxplot(df, x = "dose", y = "len", width = 0.8)
It produces plot:
I need to have more ticks on y
axis. I need to be able to set a custom number of the ticks that will be displayed on y
axis. For example to make display on y
axis 5, 10, 15, 20, 25, 30
ticks. How can set the number of ticks for y
axis that I need?
Upvotes: 0
Views: 1352
Reputation: 2071
To add more ticks you need to specify the values manually to the breaks
argument of any scale_*_continuous()
function.
library(ggpubr)
#> Loading required package: ggplot2
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
# Load data
data("ToothGrowth")
df <- ToothGrowth
# Basic plot
ggboxplot(df, x = "dose", y = "len", width = 0.8) +
scale_y_continuous(breaks = seq(5, 30, 5))
If you only wanted the ticks to be present but wanted to control which labels were displayed, you could do something like the following with the labels
argument by passing a parsing function.
ggboxplot(df, x = "dose", y = "len", width = 0.8) +
scale_y_continuous(breaks = seq(5, 30, 5), labels = function(x){
case_when(x%%10==0 ~ as.character(x),
TRUE ~ "")
})
Created on 2021-05-11 by the reprex package (v1.0.0)
Upvotes: 2