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

potential issue: legend text cutting off, not wrapping #82

Open
MrichardsPSRC opened this issue Mar 9, 2023 · 1 comment
Open

potential issue: legend text cutting off, not wrapping #82

MrichardsPSRC opened this issue Mar 9, 2023 · 1 comment

Comments

@MrichardsPSRC
Copy link

own_race_income_chart <- static_bar_chart(t=dt_2021_simprace,
x="share", y="income_cat",
fill="HRACE",
pos="dodge",
est="percent",
# moe="share_moe",
# href="ref_val", hrefnm="Region",
# hrefcl='#00716c',
title="Regional Homeownership by Income and Race/Ethnicity",
subtitle=NULL,
source=paste("U.S. Census Bureau, American Community Survey (ACS) 2021 1-Year Public Use Microdata Sample (PUMS)"),
alt=NULL,
xlabel=NULL, ylabel=NULL,
dec = 2, color="psrc_light") #+ theme(legend.position = "none") + scale_x_discrete(limits=rev) #alphabetical order

own-race-income-chart-1

This could be because I set the Rmarkdown to include Christy's suggested setting : {r own-race-income-chart, fig.width=10}

When I generate it in Rstudio:
image

@jensenmj
Copy link
Collaborator

jensenmj commented Mar 9, 2023

We can wrap the text by specifying the length,
c <- c + ggplot2::scale_color_discrete(labels = function(x) stringr::str_wrap(x, width = 15))
The trick here is to know how long and under what circumstances.

Taking a step back, though, I'd suggest more charts without legends at all: axis labels or even annotations within the chart are better for intuitive storytelling with data. If legend entries require wrapping, it busies things and makes quick association with the color harder. Everyone is mentally reducing that 48-character label to something shorter anyway; why not edit it down?

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

2 participants