zmeers / ggparliament

Simple parliament plots using ggplot2
https://zmeers.github.io/ggparliament/
Other
150 stars 13 forks source link

Warning: Ignoring unknown aesthetics: type #21

Closed zmeers closed 6 years ago

zmeers commented 6 years ago

I think this occurs because the type call in the aes isn't actually mapped to data. Aesthetics transform the data and type does not... It's really there so we don't have to specify type in the additional calls later on. I'm not really sure what to do here... Either we keep it as it is even though it's not really correct or we go back to defining the type in draw_majoritythreshold() and draw_partylabels()

zmeers commented 6 years ago

I think we need to revert back to the previous way of defining the parliament style in the draw_...() functions. It is unfortunate, but I think in the long run it will create more issues for us fixing a "bug" that has been sent to CRAN and other users receive warnings when they try to plot their ggparliament object. What do you think @RobWHickman ?

RobWHickman commented 6 years ago

I wonder if there's a way to map the type of parliament onto the data. My brain is too fried at the moment to think of any other than an extra column of 'type' which is obviously a bad idea.

Otherwise, I wonder if the x/y positions of the 'seats' can imply the type? But I cant really think of a good way to do that either.

A final other option might be to kind of do what the original package did where the user calls a function that wraps ggplot() + geoms() + scales() + ... but again, seems suboptimal.

Think you might be right that going back to defining the type each line is the best way but something about it sets my teeth on edge

zmeers commented 6 years ago

Another option is we get draw_...() to recognize where to print regardless of the type. For example, draw_totalseats() can be rewritten so the y coordinate for the total seats label is 25% of the height of y axis. Then we wouldn't need to specify y = 3 and y = 0.2 for horseshoe and semicircle parliaments, respectively.

The same goes for party labels - I wonder if we can move outwards from the last row using percentage points or unit points or whatever.

If you look at the majority threshold function, it kind of already works like this.. The opposing bench style finds the x and y coordinates for n, the majority threshold number, and draws a line between the the minimum value for x and the maximum value for x given that y is the same as the y coordinate for n.

I tried to figure out how to do this for horseshoe and semicircle but I kind of gave up, LOL. The main issue was that the minimum value for x,y start at (0,0) because the plot starts at that point instead of at (0, min(row 1 for majority threshold)). We should be able to find the point for n, then find the closest row 1 and the max row nearest to n, then draw a line from min(y coord for row) - 0.5 to max(y coord for row) + 0.5.

If we can solve that issue, the only problem is that the opposing bench line is horizontal, not vertical. But I've been thinking about switching that around anyway, so that one bench is on top and the other is below which would fix the problem. Or we can create a switch option here, where the user can switch between horizontal or vertical orientation... Which would be much better than defining by type every time, I agree.

RobWHickman commented 6 years ago

yeah that makes sense. I think also might feed into changing the benches geom to being one plot rather than two patched together? I haven't interrogated patchwork, but I imagine drawing a line across two plots won't make it happy?