简体   繁体   中英

How to change in legend text labels using ggplot?

I want to change the labels for the values represented by red and blue points.

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

在此处输入图片说明

Rather than having the separate scale_fill_discrete call, you can instead add the labels in scale_colour_manual as follows:

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

This is because you are colour -ing the points separately, rather than changing the fill value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM