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

Plotting labels instead of markers #22

Open
urisohn opened this issue Oct 22, 2024 · 2 comments
Open

Plotting labels instead of markers #22

urisohn opened this issue Oct 22, 2024 · 2 comments

Comments

@urisohn
Copy link

urisohn commented Oct 22, 2024

Been using beeswarm for a while (e.g., in our blog Data Colada). Now using it for a new pkg that creates plots for reporting results from psychology experiments, and one of the plots we wanted to offer was the beeswarm plot, but using text-labels instead of markers.
Like. Imagine with data at the State level in the US and every 'marker' is the two letter abbreviation for the state (AZ, AK, etc.)

Karmali   Kawakami - stimulus beeswarm
You can see an example inm the uploaded plot. I ended up creating a beeswarm, without plotting, using the exprted values, and then using text() to populate it, but maybe it could be built into the package as an option. Just a suggestion.

@aroneklund
Copy link
Owner

Hmm. That's not a bad idea.

I guess you could create a simple version with something like this (which I think is what you are describing):

out <- beeswarm(state.area, log = TRUE, spacing = 4, pch = NA)
text(out$x, out$y, labels = state.abb)

Here I set spacing = 4 based on trial and error. I think this works pretty well with state abbreviations, since they are all around the same size.

Are you proposing a more automatic approach, such as taking the size of each individual label into account when doing the layout? (maybe similar to #5 but with text instead of points?)

@urisohn
Copy link
Author

urisohn commented Oct 23, 2024

Yes, that's basically what i did, but i think some automatic spacing would be needed to prevent overstepping too much
i find it hard to navigate the mapping between text and absolute dimensions so could be tricky

The hacky way I did was to compute the average length of the labels and convert that to the horizontal spacing.
LIke this

 stimulus.length = mean(nchar(ms$stimulus))
  dot.spacing = stimulus.length/3 + 2

where ms$stimulus contains the labels you see, and then i make spacing=dot.spacing inside the beeswarm call

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