0
votes

I have the following chart:

ggplot(data = centmerge, aes(x=long, y=lat, group = centmerge$group)) +
geom_polygon(stat = "identity", fill = "green", color = "black") +
geom_point(data = centavg, aes(x = long, y = lat, group = Performance.Country.Name, size = Action_Absolute_Value/1000000))+  
ggtitle("Contract Costs") +
coord_map("polyconic")+
theme(axis.text.y = element_blank(), axis.text.x = element_blank(), axis.title.x=element_blank(), 
axis.title.y=element_blank())

It creates the following chart:

enter image description here

My problem is that I cannot alter any of the aesthetics of the geom_point. For instance I cannot change the color of the points on the graph and I cannot change the legend title. All additions such as the:

theme(axis.text.y = element_blank(), axis.text.x = element_blank(), axis.title.x=element_blank(), 
    axis.title.y=element_blank())

at the end will affect only the geom_polygon(). If I try to change the color of the circles, it reverts to a pale red but then I cannot change it further, and I have had no luck changing the title using theme(), scale_fill_discrete(), labs() or any method. I first want to change the legend title, but also the color of the circles on the map. I can change the color of the map, but not the circles.

2
Did you try theme(legend.title = element_blank())? And labs(fill="New name of legend title")lawyeR
You can also create a variable in your data frame for Action_Absolute_Value/1000000), name that variable what you want the legend title to be, and solve your naming problem.lawyeR
I have tried the first method. Didn't work. The second suggestions worked but it still leaves me without a way to change the colors of the circles.user2907249
Can you not change the color of the points by putting color = "peachpuff3" inside the geom_point call? (Don't put it inside aes() as it doesn't map to a column of data.) Is there a reason you need to make these edits post-hoc?Gregor Thomas
@lawyeR no worries---though I do wish you had kept "peachpuff3" as the example color ;). I had assumed that OP did have a reason not to edit the code, I may put up a competing answer dealing with the issues in a slightly different way (though I already upvoted your answer).Gregor Thomas

2 Answers

1
votes

Drawing on the comments, here is a proposed approach.

Create a variable in your data frame for Action_Absolute_Value/1000000), name that variable what you want the legend title to be, and solve your legend-title naming problem.

As to coloring the points, per Gregor's comment, add color = "red" [or whatever color you choose] inside the geom_point call.

1
votes

You seem to have a lot of confusion about themes vs. layers. Editing the theme is good for things like the colors of axes and gridlines, but is not the preferred way to do labeling. The labs function works for labels of all dimensions, x, y, color, size, etc., as well as title.

For the color of the points, just tell geom_point what color you want.

ggplot(data = centmerge, aes(x=long, y=lat, group = centmerge$group)) +
  geom_polygon(stat = "identity", fill = "green", color = "black") +
  geom_point(data = centavg,
             aes(x = long, y = lat, group = Performance.Country.Name,
                 size = Action_Absolute_Value/1000000),
             # color goes outside of aes() because it's constant for all points
             color = "peachpuff3") +  
  coord_map("polyconic") +
  labs(x = "", y = "",
       # size will give the name for the size legend
       size = "Action Absolute Value (millions)",
       title = Contract Costs")
  theme(axis.text.y = element_blank(), axis.text.x = element_blank())