使用geom_text和geom_text_repel标记

时间:2017-10-24 12:32:00

标签: r ggplot2

我正在尝试使用Geom Text添加标签。如果我使用geom_text,我无法看到所有值。但是如果我使用geom_text_repel,我会看到所有带有重复的值。目的是看到标记所有唯一值而不重复。谁能告诉我它将如何完成?

 library(ggrepel)
 library(ggplot2)
 rr <- ggplot(data = staypoint6, aes(staypoints.Stayplon, 
 staypoints.staypLat))+
 geom_line(alpha = 0.5, size = 2, shape = 16,  width = 0.000003, height = 
 0.000003, colour ="darkgoldenrod4") +  coord_fixed (ratio = 2) +
 labs(x ="Longitude", y = "Latitude") +
 theme(axis.title = element_text(size=14), 
     panel.background = element_rect(fill = "white",size = 0.5, linetype = "dotted"),
     panel.grid.major = element_line(size = 0.5, linetype = 'dotted',colour = "black"), 
     panel.grid.minor = element_line(size = 0.5, linetype = 'dotted',colour = "black"),
     panel.border = element_rect(colour = "black", fill=NA, size=0.5),
     axis.text.y   = element_text(size=12),
     axis.text.x   = element_text(size=12)) +  geom_text(aes(label = 
     Location_ids), colour = "dodgerblue4", size=6)

   rr + geom_text(aes(label = paste0("(", staypoint6$arri_time, ",", 
   staypoint6$lev_time, ")")), check_overlap = FALSE, size=4, hjust=0.15, 
   vjust=2)

enter image description here

   rr + geom_text_repel(aes(label = paste0("(", staypoint6$arri_time, ",", 
   staypoint6$lev_time, ")")), check_overlap = FALSE, size=4, hjust=0.15, vjust=2)

enter image description here

0 个答案:

没有答案