Reputation: 1671
How can I remove the first y axis label, here $0
but keep the default labels otherwise ?
library(ggplot2)
library(scales)
y <- data.frame(
group = c("GROUP A", "GROUP A", "GROUP A", "GROUP B", "GROUP B", "GROUP B"),
individual = c("Individual 1", "Individual 2", "Individual 3",
"Individual 1", "Individual 2", "Individual 3"),
value = c(2000, 9000, 45000, 3500, 11500, 38000)
)
ggplot(data = y, aes(x = group, y = value)) +
geom_bar(stat = "identity") +
scale_y_continuous(labels = scales::dollar_format(accuracy = 100L)) +
facet_grid(rows = vars(individual), scales = "free")
Upvotes: 2
Views: 600
Reputation: 124148
You could make use of a custom breaks function like so:
EDIT: And thanks to @LMc if you want to stick with the default breaks you could replace breaks_pretty
with breaks_extended
following this post.
library(ggplot2)
library(scales)
y <- data.frame(
group = c("GROUP A", "GROUP A", "GROUP A", "GROUP B", "GROUP B", "GROUP B"),
individual = c("Individual 1", "Individual 2", "Individual 3",
"Individual 1", "Individual 2", "Individual 3"),
value = c(2000, 9000, 45000, 3500, 11500, 38000)
)
mybreaks <- function(x) {
x <- breaks_pretty()(x)
x[x<=0] <- NA
x
}
ggplot(data = y, aes(x = group, y = value)) +
geom_bar(stat = "identity") +
scale_y_continuous(breaks = mybreaks, labels = scales::dollar_format(accuracy = 100L)) +
facet_grid(rows = vars(individual), scales = "free")
Upvotes: 1