library(ggplot2)

#1导入数据
load(file='D:/wdata.rda')

#2基本图形架构
sp<-ggplot(wdata,aes(x=life,y=tourism))+geom_point(size=2,aes(colour=tourism))
sp

#3修订坐标轴范围
sp<-sp+ xlim(2.5, 5)+ylim(2.5, 5)
sp

#4 修改为中文的坐标轴标注
sp<-sp+labs(x = "生活中",y="旅游中",colour = "旅游中")
sp

#5a 增加象限(以3为基准)
sp3<-sp+geom_vline(xintercept=3,color = "red")+geom_hline(yintercept=3,color = "red")
sp3

#5b 增加象限(以平均分为基准)
spmean<-sp+geom_vline(xintercept=3.77,color = "red",linetype="dashed")+geom_hline(yintercept=3.94,color = "red",linetype="dashed")
spmean

#6 增加斜线(y=x)
spmean<-spmean+geom_abline(intercept = 0, slope = 1, color="red",size=1)
spmean

#7 增加中文数据点的标注
sptext<-spmean+geom_text(aes(label=structure),size=2.8,hjust=-0.1,vjust=0.2)
sptext

#8a处理数据点标注重叠问题01: check_overlap = TRUE
sptext1<-spmean+geom_text(aes(label=structure),size=2.8,hjust=-0.1,vjust=0.2,check_overlap = TRUE)
sptext1

#8b处理数据点标注重叠问题02:ggrepel package
library(ggrepel)
sptext2<-spmean+geom_text_repel(aes(label = structure), size = 4.5,hjust=-0.1,vjust=0.2) 
sptext2