Change ggplot2 colourbar tick marks to black

前端 未结 3 774
花落未央
花落未央 2021-01-02 09:26

In some of my plots I find it hard to see the tick marks in the colour bar. I haven\'t been able to find a documented way to change the colour of the ticks. All the examples

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 10:09

    The pull request mentioned in another answer never made it into the ggplot2 code base, but this is now possible in a slightly different way in the development version (slated to be released as ggplot2 2.3):

    ggplot(df, aes(x, y, fill = val)) +
      geom_raster() +
      scale_fill_gradient(low = "#FFFFFF", high = "#de2d26") +
      guides(fill = guide_colourbar(barheight = unit( 3 , "in" ),
                                    ticks.colour = "black",
                                    ticks.linewidth = 1)) +
      theme_bw() +
      theme(line = element_line(colour = "#0000FF"))
    

    You can also add a frame, which may be useful when some of the colors in the colorbar are very light.

    ggplot(df, aes(x, y, fill = val)) +
      geom_raster() +
      scale_fill_gradient(low = "#FFFFFF", high = "#de2d26") +
      guides(fill = guide_colourbar(barheight = unit( 3 , "in" ),
                                    ticks.colour = "black",
                                    ticks.linewidth = 1,
                                    frame.colour = "black",
                                    frame.linewidth = 1)) +
      theme_bw() +
      theme(line = element_line(colour = "#0000FF"))
    

提交回复
热议问题