Hi. First of all, please read FAQ: What's a reproducible example ( reprex
) and how do I create one?
Your error appears because you trying to supply your data to ggplot()
twice. You have to choose either you use pipe or define data inside ggplot()
in a classical way.
# Bad
x %>%
ggplot(x, aes(x=1, y=Freq, fill=factor(korpus1))) +
geom_col(position = 'stack', width = 1)
# Good
x %>%
ggplot(aes(x=1, y=Freq, fill=factor(korpus1))) +
geom_col(position = 'stack', width = 1)
# Good
ggplot(x, aes(x=1, y=Freq, fill=factor(korpus1))) +
geom_col(position = 'stack', width = 1)
I also can spot two additional mistakes: you should not use aes()
inside theme()
and labs()
.
Perhaps, it should work in the following way, but I can't check without sample data.
ggplot(x, aes(x=1, y=Freq, fill=factor(korpus1))) +
geom_col(position = 'stack', width = 1) +
geom_text(aes(label = paste(round(Freq / sum(Freq) * 100, 1), "%"),
x = 1.3),
position = position_stack(vjust = 0.5)) +
theme_classic() +
theme(plot.title = element_text(hjust=0.5),
axis.line = element_blank(),
axis.text = element_blank(),
axis.ticks = element_blank()) +
labs(fill = "korpus1",
x = NULL,
y = NULL,
title = "Tortendiagramm") +
coord_polar("y")