R语言绘制样本分布图

 

1、

library(ggplot2)
Beijing <- c(116,40)    ## 经纬度信息
Tokyo <- c(139, 36)
Paris <- c(2, 48)
Sydney <- c(150, -33)
Newyork <- c(-74, 40)

dat <- as.data.frame(rbind(Beijing, Tokyo, Paris, Sydney,Newyork))
names(dat) <- c("long","lat")      ## 生成数据框

ggplot(data =  dat, aes(x = long, y = lat)) + 
  borders("world", col = "grey",size= 0.5) + geom_point(cex = 4, col = c("blue", "red", "green", "purple", "cyan")) +
  geom_text(label = c("AA", "BB", "CC", "DD","EE"),cex = 4,
            fontface = "bold",family = "sans", hjust= -0.5,vjust=0.5)  + scale_y_continuous("Latitude") + 
  scale_x_continuous("Longitude") +  theme_bw()  + theme(panel.grid=element_blank()) +
  theme(panel.border = element_rect(fill=NA,color="black", size=1.5, linetype="solid")) + 
  theme(axis.title.y=element_text(vjust=0.5, hjust = 0.5,size=25,face = "bold"),
        axis.text.x=element_text(vjust= 0,hjust = 0.5, size=15,face = "bold"),
        axis.text.y=element_text(vjust=0.5,hjust = 0.5,size=15,face = "bold"),
        axis.title.x=element_text(vjust=0.5,hjust = 0.5, size=25,face = "bold")) +
  theme(axis.ticks.x=element_line(color="black",size=0.8,lineend = 2)) +
  theme(axis.ticks.y=element_line(color="black",size=0.8,lineend = 2)) +
  theme(plot.margin=unit(rep(1,4),'cm'))

ggsave('distribute.png',dpi = 1080)  

 

绘图结果:

 

posted @ 2022-05-07 14:09  小鲨鱼2018  阅读(526)  评论(0编辑  收藏  举报