Everything looks good for my stacked area plot but I would like the intervals displayed on the y axis to change from 25% to 10%. It seems simple but I can't get it and any help is greatly appreciated.
Code:
ggplot(data3_long,
aes(x = fyear,
y = percentage,
fill = factor(variable,
levels = c("CHE", "IVAO", "ACO", "RECT", "AO", "INTAN", "PPENT")),
group = variable)) +
geom_area(position = 'stack') +
scale_fill_manual(values = color_palette, name = NULL) +
scale_y_continuous(name = "Percentage", labels = scales::percent_format()) +
labs(x = "Year", title = "Test") +
theme_minimal() +
theme(legend.position = "bottom") +
guides(fill = guide_legend(nrow = 1))
I tried adding breaks and it didn't work:
scale_y_continuous(breaks = seq(0, 100, by=10), limits=c(0,100))
Accuracy didn't work either but I did not expect it to. Thanks again.
One can use the breaks
argument in scale_y_continuous
with percentages as fractions of 1.0. As the example missed a reproducible data set, I create some simple test data:
library(ggplot2)
## a reproducible data set
df <- data.frame(
x = 1:10,
y = runif(30),
g = factor(rep(1:3, each = 10))
)
## simplified plot, concentrating on the necessary parts
ggplot(df, aes(x=x, y=y, fill=g)) +
geom_area(position='stack') +
scale_y_continuous(name = "Percentage",
labels = scales::percent_format(),
breaks = seq(0, 1, 0.1))