tpemartin / 110-1-Economic-Data-Visualization

https://tpemartin.github.io/110-1-Economic-Data-Visualization/
MIT License
1 stars 18 forks source link

geom_rug as axis ticks. #12

Open tpemartin opened 2 years ago

tpemartin commented 2 years ago
breaks = c(
  1979,
  seq(1985, 2015, by=5),
  2018
)
labels = c(
  "1979", "85", "90", "95", "2000", "05", "10", "15", "18"
)
ggplot1 <- list()

ggplot()+
  geom_step(
    data=dataSet1,
    mapping=
      aes(
        x=x,
        y=y
      )
  ) -> ggplot1$plot0
ggplot1$plot0

x=interger x=discrete scale_x_discrete scale_x_continuous

Fine tune x scale

ggplot1$plot0 +
  scale_x_continuous(
    breaks=breaks,
    labels=labels
  ) -> ggplot1$plot1

ggplot1$plot1
ggplot1$plot1 +
  theme(
    axis.ticks.length.x=unit(0, "mm")
  ) -> ggplot1$plot2

ggplot1$plot2
bigyears <- 
  seq(1980, 2015, by=5)
smallyears <-
  seq(1979, 2018)
ggplot1$plot2 +
  geom_rug(
    aes(
      x=bigyears
    ),
    outside = T,
    length=unit(
      2, #input$bigT
      "mm"
    )
  ) +
  geom_rug(
    aes(
      x=smallyears
    ),
    outside = T,
    length=unit(
      1, #input$smallT
      "mm"
    )
  )+
  coord_cartesian(clip="off")