zmeers / ggparliament

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

Differing number of rows error #54

Open aidanmchugh02 opened 9 months ago

aidanmchugh02 commented 9 months ago

I am attempting to build an R app that pulls election data from my SQL database and creates visualizations using the ggparliament package. I have built in methods for filtering the data to one house-country-year dataframe, which has all of the necessary variables for running the parliament_data() function. However, when I attempt to run my dataframe through this function, I get the "Error in data.frame(..., check.names = FALSE) : arguments imply differing number of rows: 0, 435" message, which prevents me from successfully creating the dataframe needed to create the plot. I have tried dozens of different iterations, removing all extraneous columns and NA values, but for some reason I cannot seem to get past this issue.

This is a screenshot of the dataframe I am attempting to pass through the function. I have even tried formatting the column names and order to be identical to the examples, but the error persists.

image

Please let me know if anyone else has had a similar problem, or if there is a workaround I have not tried yet. Some of the code and the data are proprietary for my work so I cannot share everything but happy to provide some additional information if needed. Thank you!

zmeers commented 9 months ago

Hi Aidan - thank for letting us know. I haven't actively worked on this project for a while, but I will take a look this week and get back to you :)

aidanmchugh02 commented 9 months ago

Thank you! I will keep working on it as well, and let you know if I find anything!

aidanmchugh02 commented 9 months ago

As far as I can tell, the issue arises in the parliament_data function somewhere around here:

if (!is.null(election_data)) { if (type != "opposing_benches") { parl_data <- as.data.frame(election_data[rep(row.names(election_data), party_seats), ])

The party_seats variable is returning 435, but the rep(row.names(election_data) is returning zero. When I remove my election_data variable from the function it no longer throws this error. I'll keep digging to figure out why it is returning 0 for row.names()

aidanmchugh02 commented 9 months ago

I think I'm close as far as identifying the location of the problem, when I run an opposing benches election I get different errors

Error in -group : invalid argument to unary operator In addition: Warning message: In max(parl_layout[[1]]$x + spacer) : no non-missing arguments to max; returning -Inf