no color in my congress graph

Data Society – Home Forums Clustering and finding patterns no color in my congress graph

This topic contains 2 replies, has 2 voices, and was last updated by  Elizabeth 2 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #19530


    Hi ,
    I ran this code along with the video, but instead of red and blue collars, I got “b” for democratic and “r” for republicans. I think I did it right…any ideas?
    ggplot(house_votes_Dem, aes(x=aye, y=nay, shape= partycluster.dem)) +
    geom_point(size=6) +
    ggtitle(“Aye vs Nay Dem Votes”) +
    xlab(“Aye Votes”) +
    ylab(“Nay Votes”) +
    scale_shape_manual(name =”party”,
    labels= c(“Democrat”, “Republican”),
    values= c(“blue”, “red”)) +


    Hi Elizabeth,

    Thank you for your question! So here is the code for the graph I think you’re trying to create (from slide 65):

    ggplot(house_votes_Dem, aes(x = yea, 
                                y = nay,
                                color = party_labels_Dem,  #<- tell R how to color 
                                #   the data points
                                shape = party_clusters_Dem)) + 
      geom_point(size = 6) +
      ggtitle("Aye vs. Nay votes for Democrat-introduced bills") +
      xlab("Number of Aye Votes") +
      ylab("Number of Nay Votes") +
      scale_shape_manual(name = "Cluster", 
                         labels = c("Cluster 1", "Cluster 2"),
                         values = c("1", "2")) +
      scale_color_manual(name = "Party",         #<- tell R which colors to use and
                         #   which labels to include in the legend
                         labels = c("Democratic", "Republican"),
                         values = c("blue", "red")) +

    There are a few things you may notice here. The first is that there is a ‘color’ argument in the aes() layer at the beginning of the code, which will allow the graph to color particular points. So make sure to include that in your aesthetics layer. The second aspect I wanted to point out is that your scale_shape_manual is telling R to use the letters ‘b’ and ‘r’ (in the values argument) as the shape. I think you want to use the values of 1 and 2 to get those two shapes to correspond to the cluster labels of 1 and 2. You can then add the scale_color_manual() argument to specify the colors you want for the two different political parties.

    Ggplot2 can always be a bit tough to get the hang of – I always like to think of ggplot2 as a graph with layers on it. So the aesthetics layer is the bottom layer that defines the data we want on there, and then we add layers on it like the labels, shapes, colors, legends, etc.

    Please let me know if this helps!





    Thank you so much! can’t believe I missed that …grrrr….
    Thanks again!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.