如何使用ggplot更改图例文本标签?

时间:2019-08-23 14:26:14

标签: r ggplot2 label axis

我想更改由红色和蓝色点表示的值的标签。

#Number and names of variables

[1] "Date"                         "AOD_500nm"                    
"Fine_Mode_AOD_500nm.tau_f."   "Coarse_Mode_AOD_500nm.tau_c."




#create the plot

ggplot(data4, aes(x = AOD_500nm)) +
geom_point(aes(y = Fine_Mode_AOD_500nm.tau_f., colour = 
"Fine_Mode_AOD_500nm.tau_f.")) +
geom_point(aes(y = Coarse_Mode_AOD_500nm.tau_c., colour = 
"Coarse_Mode_AOD_500nm.tau_c.")) +
labs(x = "AERONET AOD (500nm)", y = "SDA AOD (500nm)", colour = "Mode" ) +
scale_colour_manual(values = c("red", "blue")) +
scale_fill_discrete(labels = c("Coarse", "Fine")) +
theme(legend.position=c(0.9, 0.9)) +
theme(axis.text.x=element_text(size = 10,hjust=1)) +
theme(axis.text.y=element_text(size = 10)) +
theme(axis.title.x = element_text(size = 12)) +
theme(axis.title.y = element_text(size = 12))

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以单独在scale_fill_discrete中添加标签,而不必单独进行scale_colour_manual调用:

scale_colour_manual(values = c("red", "blue"), labels = c("Coarse", "Fine"))

这是因为您正在colour单独对点进行运算,而不是更改fill的值。