I have some plots where I want to break the x or/and y axes by different n's. In order to achieve this I have a dozen of functions like:
by_two <- function(x) {
  seq(0, max(x), by = 2)
}
Which I pass for each plot:
p1 <- ggplot(users_d_total %>% filter(isSame, D_rank == 2), aes(x = D, fill = as.factor(train_user_id))) +
  geom_density(alpha = .3) +
  labs(title = paste0("Without Normalization Analysis [K = 2]")) + 
  scale_fill_discrete(name = "Users") +
  scale_x_continuous(breaks = by_two)
When I try to do it simpler:
by_n <- function(x,n) {
      seq(0, max(x), by = n)
    }
But when I pass by_n with n = 0.5 or 1 or any other positive number I get an error for wrong type.
p1 <- ggplot(users_d_total %>% filter(isSame, D_rank == 2), aes(x = D, fill = as.factor(train_user_id))) +
  geom_density(alpha = .3) +
  labs(title = paste0("Without Normalization Analysis [K = 2]")) + 
  scale_fill_discrete(name = "Users") +
  scale_x_continuous(breaks = by_n(1))
Please advise how to make this smarter solution feasible.
 
    
