Home > Net >  Set axis in ggplot2 like in plot
Set axis in ggplot2 like in plot

Time:11-10

is there a way to set axis in ggplot2 in this way (made with plot())?

Thank you in advance

enter image description here

CodePudding user response:

It's not clear what aspect you are looking for, so here's a recreation of every aspect:

library(ggplot2)

ggplot()  
  geom_function(fun = function(x) x, color = NA, na.rm = TRUE)  
  scale_y_continuous(breaks = c(-450, -300, -20, 0, 300, 450), 
                     limits = c(-500, 500), name = NULL, expand = c(0, 0),
                     labels = c(-450, -300, -20, "", 300, 450))  
  scale_x_continuous(limits = c(2014.5, 2019.5),  expand = c(0, 0),
                     breaks = 2015:2019, name = NULL)  
  annotate('segment', x = 2014.5, y = -450, xend = 2014.5, yend = 450, size = 1)  
  annotate('segment', x = 2015, y = -500, xend = 2019, yend = -500, size = 1)  
  theme_classic(base_size = 16)  
  theme(axis.line = element_blank(),
        axis.ticks.length = unit(3, 'mm'))

enter image description here

  •  Tags:  
  • r
  • Related