zmeers / ggparliament

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

order of parties? #2

Closed duleise closed 6 years ago

duleise commented 7 years ago

hi I have been trying to plot this kind of seat diagram for a long time. Thank you for such a powerful tool. It works well. I have a confusion though. It seems to me that the order of parties in the graph is the same, or has to be the same as the order in the data, d or d2. As you did in your examples, Party in d is a factor, but the labels seems not work. My codes are like this:

d <- data.frame(Party = factor(c("V","S","MP","KD","C","FP","M","SD","NYD"),
                               levels = c("V","S","MP","KD","C","FP","M","SD","NYD")),
                Number = c(21,113,25,16,22,19,84,47,2))

party.color.scale.color <- scale_color_manual(values = c("V" = "#b00000",
                                                       "S" = "#EE2020",
                                                       "MP" = "#80AA4E",
                                                       "SD" = "#fedf09",
                                                       "NYD" = "grey50",
                                                       "C" = "#39944A",
                                                       "FP" = "#0069b4",
                                                       "KD" = "#2D338E",
                                                       "M" = "#52bcec"),
                                            breaks = c("V","S","MP","KD","C","FP","M","SD","NYD"))

p <- ggparliament(d
                  ,party = Party
                  ,seats1 = Number
                  ,style = "dots"
                  ,label = "both"
                  ,size = 4
                  ,nrows = 10
                  ,total = 6
                  )
p <- p + theme_void() + theme(legend.title = element_blank())
p <- p + party.color.scale.color
p

Both color and seat number is correct. That was done by manually sorting the parties in d. Also, when I chose label = "both", the party names and seat number are mismatched. Any suggestion how I can improve this? Thanks again.

RobWHickman commented 6 years ago

this should be fixed in the new pull request. Parties should be plotted by number of seats and then whether or not they are "in power/government" which can be specified (see README)