Skip to content

Axis labels accept plotmath expressions #4615

Closed
@dmurdoch

Description

@dmurdoch

This is a doc suggestion.

The axis labelling functions like scale_y_continuous() have a labels argument. This argument accepts plotmath expressions, but is not documented to do so.

df <- data.frame(x=1:3, y=c(1,10,100))
library(ggplot2)
ggplot(df, aes(x=x, y=y)) +
  geom_point() +
  scale_y_continuous(breaks=c(1,10,100),
                     labels=expression(10^0, 10^1, 10^2))

The docs say

labels
One of:

  • NULL for no labels
  • waiver() for the default labels computed by the transformation object
  • A character vector giving labels (must be same length as breaks)
  • A function that takes the breaks as input and returns labels as output. Also accepts rlang lambda function notation.

I'd add

  • An expression vector (must be the same length as breaks). See ?plotmath for details.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions