如何在此代码中添加图例?
谢谢!
ggplot()+
geom_point(data=avg_harv_df, aes(x=samp_per, y=ndvi), size=3, color='red') +
geom_point(data=avg_sjer_df, aes(x=samp_per, y=ndvi), size=3, color='blue') +
ylab("NDVI")+
xlab("Sampling period")
答案 0 :(得分:0)
选项1:
ggplot()+
geom_point(data=avg_harv_df, aes(x=samp_per, y=ndvi, col = "a"), size=3) +
geom_point(data=avg_sjer_df, aes(x=samp_per, y=ndvi, col = "b"), size=3) +
ylab("NDVI")+
xlab("Sampling period")
选项2:
combined <- dplyr::bind_rows(avg_harv_df, avg_sjer_df, .id = 'col')
ggplot(combined, aes(x=samp_per, y=ndvi, col = col))+
geom_point(size=3) +
ylab("NDVI")+
xlab("Sampling period")
我几乎总是喜欢选项2。