Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The bar labelling is not displayed on both sides of the pyramid chart #102

Open
KrichevAI opened this issue Apr 18, 2024 · 0 comments
Open

Comments

@KrichevAI
Copy link

KrichevAI commented Apr 18, 2024

When I try to add geom_text to the pyramid chart, the text only appears on one side of the bar chart (on the right). Changing the hjust setting does not help.

Example:

data <- data.frame(
  age_category = rep(c("18-29"), 2),
  gender = rep(c("Female", "Male"), each = 1),
  percentage = c(40,60) # Positive values for percentages
)
pyramid_plot <- pyramid_plot + 
  geom_text(data = subset(data, gender == "Female"), 
            aes(label = sprintf('%0.1f%%', abs(percentage)), y = -abs(percentage)/2),
            hjust = -0.5, size = 3) +
  # Add text annotations for males
  geom_text(data = subset(data, gender == "Male"), 
            aes(label = sprintf('%0.1f%%', percentage), y = percentage/2),
            hjust = 0.5, size = 3)
Screenshot 2024-04-18 at 10 25 57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant