I am trying to create a graph, but for some reason the data labels are the breakdown of every data point on the graph. Not sure what is going on here. here's the code I'm using. I would appreciate any help with this.
incentive_select %>%
count(invest_reward = factor(invest_reward)) %>%
mutate(pct = n/sum(n)) %>%
ggplot(aes( x = invest_reward, y= pct,
label = scales::percent(pct)))+
geom_col(fill = "steelblue") +
geom_text(vjust = -1,
size = 3) +
scale_y_continuous(labels = scales::percent) +
labs(
x = "How much do you agree with the following statements about solar
incentives and net metering? \n Only people who are investing in rooftop
solar panels should be rewarded for their contribution to clean
energy generation."
) +
theme(axis.title.y=element_blank(),
axis.text.x = element_text(vjust = 0.5, hjust=1))
incentive_select %>% select(invest_reward,
more_support,
pay_fee) %>%
count(invest_reward = factor(invest_reward),
more_support = factor(more_support),
pay_fee = factor(pay_fee)) %>%
mutate(pct = n/sum(n)) %>%
rename("Only people who are investing in rooftop solar panels
should be rewarded for their contribution to clean energy generation" = "invest_reward",
"More support should be provided to those who don’t have
access to rooftop solar" = "more_support",
"Incentives are too high for rooftop solar panels owners.
They should pay a fee for sending power to the grid" = "pay_fee") %>%
pivot_longer(cols = c("Only people who are investing in rooftop solar panels \nshould be rewarded for their contribution to clean energy generation",
"More support should be provided to those who don’t have\naccess to rooftop solar",
"Incentives are too high for rooftop solar panels owners.\nThey should pay a fee for sending power to the grid")) %>%
group_by(name) %>%
ggplot(aes(x = value, y= pct, fill = name,
label = scales::percent(pct)))+
geom_col() +
facet_wrap(~name, ncol = 1) +
geom_text(aes(label = pct), position = position_stack(vjust = 0.5),
size = 3, color = "white", check_overlap = TRUE) +
scale_y_continuous(labels = scales::percent) +
scale_x_discrete(labels = label_wrap_gen(width = 25, multi_line = TRUE)) +
labs(y = "Percentage",
title = "How strongly do you agree with the proposed rooftop solar
incentive reforms in your local jurisdiction?") +
theme(axis.title.x=element_blank(),
axis.text.x = element_text(vjust = 0.5, hjust=1),
legend.position = "bottom")