scale_x_comma: Axis scales format

Description Usage Arguments Value Examples

View source: R/other_plots.R View source: R/other_plots.R

Description

The _comma ones set comma format for axis text, the _percent ones set percent format for axis text, _dollar for collar currency, and _abbr for abbreviated format. Lastly, use _formatNum to further customize your numerical scales with lares::formatNum.

The _comma ones set comma format for axis text, the _percent ones set percent format for axis text, _dollar for collar currency, and _abbr for abbreviated format. Lastly, use _formatNum to further customize your numerical scales with lares::formatNum.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
scale_x_comma(...)

scale_y_comma(...)

scale_x_percent(...)

scale_y_percent(...)

scale_x_dollar(...)

scale_y_dollar(...)

scale_x_abbr(...)

scale_y_abbr(...)

scale_x_formatNum(
  ...,
  decimals = 2,
  signif = NULL,
  type = Sys.getenv("LARES_NUMFORMAT"),
  pre = "",
  pos = "",
  sign = FALSE,
  abbr = FALSE
)

scale_y_formatNum(
  ...,
  decimals = 2,
  signif = NULL,
  type = Sys.getenv("LARES_NUMFORMAT"),
  pre = "",
  pos = "",
  sign = FALSE,
  abbr = FALSE
)

scale_x_comma(...)

scale_y_comma(...)

scale_x_percent(...)

scale_y_percent(...)

scale_x_dollar(...)

scale_y_dollar(...)

scale_x_abbr(...)

scale_y_abbr(...)

scale_x_formatNum(
  ...,
  decimals = 2,
  signif = NULL,
  type = Sys.getenv("LARES_NUMFORMAT"),
  pre = "",
  pos = "",
  sign = FALSE,
  abbr = FALSE
)

scale_y_formatNum(
  ...,
  decimals = 2,
  signif = NULL,
  type = Sys.getenv("LARES_NUMFORMAT"),
  pre = "",
  pos = "",
  sign = FALSE,
  abbr = FALSE
)

Arguments

...

Arguments passed to ggplot2::continuous_scale or lares::formatNum depending on the function.

decimals

Integer. Amount of decimals to display.

signif

Integer. Rounds the values in its first argument to the specified number of significant digits.

type

Integer. 1 for International standards. 2 for American Standards. Use Sys.setenv("LARES_NUMFORMAT" = 2) to set this parameter globally.

pre

Character. Add string before or after number.

pos

Character. Add string before or after number.

sign

Boolean. Add + sign to positive values.

abbr

Boolean. Abbreviate using num_abbr()? You can use the ‘decimals' parameter to set abbr’s n(-1) parameter.

Value

Reformatted scales on ggplot2 object

Reformatted scales on ggplot2 object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
library(ggplot2)
df <- ggplot2::txhousing %>% removenarows(all = FALSE)

ggplot(df, aes(x = sales, y = volume)) + geom_point() +
  scale_x_dollar() + scale_y_abbr()
  
# Use any argument from scale_x/y_continuous
ggplot(df, aes(x = listings, y = log(inventory))) + geom_point() +
  scale_x_comma() + scale_y_percent(limits = c(0, 3))
  
# Use any argument from scale_x/y_continuous AND formatNum
ggplot(df, aes(x = median, y = inventory)) + geom_point() +
  scale_x_formatNum(n.breaks = 3, pre = "@", abbr = TRUE) +
  scale_y_formatNum(position = "right", decimals = 0, pos = " X")
library(ggplot2)
df <- ggplot2::txhousing %>% removenarows(all = FALSE)

ggplot(df, aes(x = sales, y = volume)) + geom_point() +
  scale_x_dollar() + scale_y_abbr()
  
# Use any argument from scale_x/y_continuous
ggplot(df, aes(x = listings, y = log(inventory))) + geom_point() +
  scale_x_comma() + scale_y_percent(limits = c(0, 3))
  
# Use any argument from scale_x/y_continuous AND formatNum
ggplot(df, aes(x = median, y = inventory)) + geom_point() +
  scale_x_formatNum(n.breaks = 3, pre = "@", abbr = TRUE) +
  scale_y_formatNum(position = "right", decimals = 0, pos = " X")

lares documentation built on June 9, 2021, 9:06 a.m.