Reputation: 25
I'd like to show y-axis negative values in parentheses rather than with a negative sign. For example, rather than -2,000 I'd like to show (2,000). I'm using ggplot2 in R.
I've tried using "negative_parens = TRUE" inside of scale_y_continuous as shown below without success.
ggplot(dataset, aes(x=date, y=value, group = variable, color = variable,
size = variable))+geom_line()+
scale_size_manual(values =c(1.5, 1.5, 1.5))+
theme_light(base_size = 16)+scale_y_continuous(labels =
comma_format(negative_parens = TRUE), limits = c(-3500, 6000))
The code above does not throw an error, but still returns a y-axis labeled with negative signs rather than parentheses. Any tips on how to get negative values to appear in parentheses on the y-axis? Any help is appreciated.
Upvotes: 2
Views: 788
Reputation: 66870
I believe scales::dollar_format
has that negative_parens
option but the other formats like scales::comma_format
do not. (As of current v0.4.1)
Should work with:
scale_y_continuous(
labels = scales::dollar_format(negative_parens = TRUE, prefix = ""),
limits = c(-3500, 6000)
)
For example:
ggplot(mtcars, aes(x=wt, y=mpg - mean(mpg)))+
geom_point()+
scale_y_continuous(
labels = scales::dollar_format(negative_parens = TRUE,
prefix = "")
)
Upvotes: 4