Make every Nth axis label bold with ggplot2

前端 未结 1 800
悲&欢浪女
悲&欢浪女 2021-02-09 18:36

Is it possible to make every Nth tick on an axis bold using ggplot2? I only want to have the axis tick bold (the small line), not the text.

This would be useful for high

1条回答
  •  别跟我提以往
    2021-02-09 19:28

    You can try:

    ggplot(df, aes(x=date, y=value, color=variable)) + 
         geom_line() + 
         scale_color_manual(values = c("#00ba38", "#f8766d")) +
         scale_x_date(date_breaks = "1 year", date_labels ="%Y") +
         theme(axis.ticks.x = element_line(colour = "black", size = c(5, rep(1,5))),
           axis.text.x = element_text(angle = 90, vjust=0.5, size = c(15,rep(8,5))))
    

    used every 6th and text size for illustration purposes. You can also use your breaks and labels but then you have to use following instead as you duplicated all breaks and labels and they must priorly removed.

    scale_x_date(labels = lbls[!duplicated(lbls)], breaks = brks[!duplicated(lbls)]) 
    

    0 讨论(0)
提交回复
热议问题