R 无法更改分层ggplot中的图例标题

R 无法更改分层ggplot中的图例标题,r,ggplot2,R,Ggplot2,我有以下图表: 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_Absol

我有以下图表:

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())
它将创建以下图表:

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())

我的问题是我不能改变geom_点的任何美学。例如,我无法更改图形上点的颜色,也无法更改图例标题。所有添加项,例如:

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

最后将仅影响几何多边形()。如果我尝试更改圆圈的颜色,它会恢复为淡红色,但我无法进一步更改它,而且我没有运气使用theme()、scale\u fill\u discrete()、labs()或任何方法更改标题。我首先要更改图例标题,还要更改地图上圆圈的颜色。我可以改变地图的颜色,但不能改变圆圈

根据这些评论,这里是一个建议的方法

在数据框中为操作(绝对值/1000000)创建一个变量,将该变量命名为您希望的图例标题,并解决图例标题命名问题


至于点的颜色,根据Gregor的评论,在geom_point call中添加
color=“red”
[或您选择的任何颜色]。

您似乎对主题与层有很多混淆。编辑主题有利于轴和网格线的颜色,但不是做标签的首选方式。
labs
功能适用于所有尺寸、x、y、颜色、大小等以及标题的标签

对于点的颜色,只需告诉
geom_point
您想要什么颜色

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())

您是否尝试过主题(legend.title=element_blank())?和labs(fill=“New name of legend title”)您还可以在数据框中为操作\绝对\值/1000000创建一个变量,将该变量命名为您希望的图例标题,并解决命名问题。我尝试了第一种方法。没用。第二个建议奏效了,但它仍然让我无法更改圆圈的颜色。您能否将
color=“peachpuff3”
放入geom_point call中来更改点的颜色?(不要把它放在
aes()
中,因为它不会映射到一列数据。)你有必要在事后进行这些编辑吗?@lawyeR不用担心——尽管我真希望你保留“peachpuff3”作为示例颜色;)。我假设OP有理由不编辑代码,我可能会提出一个与之竞争的答案,以一种稍微不同的方式处理这些问题(尽管我已经对你的答案投了赞成票)。这对重命名图例很有效,谢谢。虽然现在我需要不带空格的命名(即Value\u Amount)。有点难看,但比以前好多了。