-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix how geom_dotplot handles some aes #1096
Conversation
This commit allows geom_dotplot to display color attributes properly when dots are binned. Prior to this, if one ran a command such as: ggplot(mtcars, aes(x=factor(cyl), y =mpg, fill=factor(carb), group=factor(cyl))) + geom_dotplot(binaxis="y", stackdir="center") The dots would be positioned on top of each other, because a "double grouping" was performed where both the fill and the x axis were used to divide groups. This change keeps the groups appropriately separated when the x/y positions are being determined, but still applies separate coloring to each. It does this by changing where the fill color is added to the data used when plotting. Previously, the data was condensed into bins and a dataframe where each row represented several dots to be plotted during the calculate groups step. This condendsed data was then re-expanded with a constant fill color added for each binned group inside the reparameterise method. This commit re-expands the data into one line per dot in the original calculate method, where the appropriate fill (or other aes) is still available and can be added back in. I verified that all the original examples for geom_dotplot still behave as expected, and all tests currently pass.
I gather the failed tests are independent of this PR as several previous ones seem to generate the same error. |
@wch could you please review the basic strategy? @evolvedmicrobe You'll also need to match the style of the existing code, but there's no point doing that until we're confident that the change as a whole is good to merge. |
A couple quick thoughts:
|
Was this closed because it was fixed? And if so, what is the solution. I still get unpredictable spacing using |
This issue was just closed and not fixed. |
Stumbled across this while trying to figure out how to produce something similar to the "after" plot above. Can see the rational for not wanting to change the default behavior, but it would be nice to have this as an option at least. |
Solution would go through feeding fill argument inside dotplot layer without calling aes(), but DATA MUST BE ORDERED FIRST, first with respect to your x variable ( factor(cyl) ), secondly with respect to your y variable (mpg). Solution would look a lot like that:
Downside is that you are losing legends, I think it can be set manually. It's possible to build a function to address the colors in a very personal way returning strings that reger RGB values or color names.
|
For what's its worth we were able to solve the problem and make a nice publication graphic (Figure 1 here: http://www.pnas.org/content/early/2017/07/12/1703338114.full.pdf). I love this library, thanks ggplot! |
This PR was closed, but it appears there is still an open issue: #1745. |
This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/ |
This commit allows geom_dotplot to display color attributes properly
when dots are binned. Prior to this, if one ran a command such as:
The dots would be positioned on top of each other, because a "double
grouping" was performed where both the fill and the x axis were used to
divide groups. This change keeps the groups appropriately separated
when the x/y positions are being determined, but still applies separate
coloring to each.
It does this by changing where the fill color is added to the data used
when plotting. Previously, the data was condensed into bins and a
dataframe where each row represented several dots to be plotted during
the calculate groups step. This condensed data was then re-expanded
with a constant fill color added for each binned group inside the
reparameterise method. This commit re-expands the data into one line
per dot in the original calculate method, where the appropriate fill
(or other aes) is still available and can be added back in.
I verified that all the original examples for geom_dotplot still behave
as expected, and all tests currently pass.