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

Let pwcex affect point layout #5

Open
AlexHmann opened this issue May 10, 2019 · 4 comments
Open

Let pwcex affect point layout #5

AlexHmann opened this issue May 10, 2019 · 4 comments

Comments

@AlexHmann
Copy link

AlexHmann commented May 10, 2019

Hi Aron,

I am a big fan of your package. For what I would need the package most for, I cannot use it unfortunately. I would need to fit tightly a set of differently-sized points. I know that you implemented the pwcex option, but this parameter is not considered for the point layout.

Any possibility you could change this without having a lot of work?
I found several forum entries online where people complain that there is no way to solve this problem in R by using existing packages (and they also mention the beeswarm package). I think by implementing this option, you'd make more people happy, than just me :)

I wrote a function myself which can solve this problem, but it is kind of slow because the point fitting depends on randomness. It also doesn't really produce balanced swarm plots, i.e. sometimes dots hang over on either side of the center line.

If it is too much work for you, do you have an idea how to solve this? I found some nice d3.js programs that do a very good job at that...
Your help would be GREATLY appreciated.

Greetings,
Alex

@aroneklund
Copy link
Owner

Hi Alex. Thanks for the suggestion. Yes, I agree this would be a nice feature. I don't know of an easy solution that works right now. I will think about the best way to implement this, but it will probably not happen quickly. Could you send links to the forums you mentioned?

@AlexHmann
Copy link
Author

Hi Aron,
great, thanks!

I wrote a question on stack overflow about this a few das ago myself actually:
https://stackoverflow.com/questions/56030827/r-alternative-to-static-force-layout-stripchart-without-overlap-different-dot-s

Where I cite these people (I found more people asking about this in other places, but can't find the links now):
https://stackoverflow.com/questions/50839239/beeswarm-plot-with-different-size-circles-in-r
https://stackoverflow.com/questions/43698290/jitter-dots-without-overlap

@ssp3nc3r
Copy link

ssp3nc3r commented Nov 6, 2019

This would be a great additional feature. Any progress been made?

@rrohwer
Copy link

rrohwer commented Mar 13, 2022

An easy implementation might be converting point cex into xsize and ysize. You can do this by:

char.height <- par("cxy")[2]
point.diam <- char.height / (2 * pi)

Here's an example to show that this conversion works for finding the point diameter in plot xy units:

char.height <- par("cxy")[2]
point.diam <- char.height / (2 * pi)
point.cex <- 7 # try changing and it still works
point.diam.cex <- point.diam * point.cex

plot(x = 0, y = 1, type = "n")
points(x = 0, y = 1, cex = point.cex, pch = 21, bg = "grey")
segments(x0 = 0 - (point.diam.cex/2), x1 = 0 + (point.diam.cex/2), y0 = 1, y1 = 1, col = "red")

However, this is still not working when I try to implement it with xswarm and I don't know why:

library(beeswarm)
ex1 <- runif(n = 20, min = -1, max = 1)
x.loc1 <- rep(1,20)
cex.1 <- runif(n = 20, min = .7, max = 2)

char.height <- par("cxy")[2]
point.diam <- char.height / (2 * pi)
point.sizes <- point.diam * cex.1

plot(x = x.loc1, y = ex1, xlim = c(.5,1.5), ylim = c(-1,1), type = "n")
jittered.x1 <- swarmx(x = x.loc1, y = ex1, xsize = point.sizes, ysize = point.sizes)
head(jittered.x1)
all.equal(jittered.x1$y, ex1)
points(x = jittered.x1$x, y = ex1, cex = cex.1, xpd = T)

I also tried jittered.x1 <- swarmx(x = x.loc1, y = ex1, xsize = max(point.sizes), ysize = max(point.sizes)) in case the xy sizes didn't take a vector, but that doesn't work either.

I feel like this solution is almost there, but maybe I'm entering xsize and ysize incorrectly somehow. Thanks for helping!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants