1

In R, I use a self-generated data frame of parties with their seats in an election.

The problem is that the parliament plot is generated correctly, but the points that form the plot are shown in black and I cannot display them with the color that corresponds to the data of the parties. Please help me.

The formula and the dataframe:

library(ggplot2)
library(ggparliament)
library(readxl)
library(dplyr)

colors = c("#783736","#7ca32f","#b59f5c","#7ed61a","#a546bd","#337d34")

parties <- c("PC","FRVS","PH","PEV","COM","CS")
seats <- c(10,2,3,2,6,7)
datos <- data.frame(parties,seats,colors)

    parties  seats  colors
1       PC    10    #38ebe8
2     FRVS     2    #2979cf
3       PH     3    #1f1f9c
4      PEV     2    #7022ab
5      COM     6    #181644
6       CS     7    #e01624

I used this formula to generate a parliament plot:

congress1 <- parliament_data(election_data = datos,
                             type = "semicircle",
                             parl_rows = 6,
                             party_seats = datos$seats)

cl <- ggplot(congreso1, aes(x = x, y = y, fill = colors)) +
  geom_parliament_seats(size=3.5) + 
  theme_ggparliament() +
  labs(fill = NULL, 
       title = "Parliament Seats") +
  scale_fill_manual(values = datos$colors, 
                    limits = datos$parties) 

cl

2 Answers2

1

I think geom_parliament_seats is parametrized for color (aka colour) not fill, and you can use scale_color_identity to use those values literally, since they are already specified in the data frame used in ggplot.

ggplot(congreso1, aes(x = x, y = y, color = colors)) +
  geom_parliament_seats(size=3.5) + 
  theme_ggparliament() +
  labs(fill = NULL, 
       title = "Parliament Seats") +
  scale_color_identity()

enter image description here

Jon Spring
  • 55,165
  • 4
  • 35
  • 53
1

We could also do it this way: change fill to color aesthetics and the corresponding scale_fill_manual to scale_color_manual:

congress1 <- parliament_data(election_data = datos,
                             type = "semicircle",
                             parl_rows = 6,
                             party_seats = datos$seats)


cl <- ggplot(congress1, aes(x = x, y = y, color = parties)) +
  geom_parliament_seats(size=3.5) + 
  scale_color_manual(values = colors, 
                     limits = parties) +
  theme_ggparliament() +
  labs(color = NULL, 
       title = "Parliament Seats")

cl

enter image description here

TarJae
  • 72,363
  • 6
  • 19
  • 66