簡體   English   中英

添加選擇的城市文本標簽-ggplot2

[英]Add select city text labels - ggplot2

如何使用ggplot2將選定的城市添加到州? 我在這里搜索了很多內容,但找不到解決方案。 以下是一些在愛荷華州按郵政編碼划分銷售機會的代碼。 我如何為得梅因和蘇城添加城市文本標簽? 我假設我使用的是geom_text行代碼? 謝謝你的幫助。

#Plot
us<-map_data('county', 'iowa')

  #Plot Map
  ggplot(c,aes(longitude,latitude)) +
    geom_polygon(data=us,aes(x=long,y=lat,group=group),color='black',fill=NA,alpha=.75)+
    #geom_point(aes(size = total), color="red3", alpha=.25)+
    geom_point(aes(size = premium), color="dodgerblue3", alpha=I(.75))+
    scale_size(name="Total Remaining Premium (000s)", labels = scales::dollar, breaks = c(25000,100000,500000,1500000),range = c(2, 40))+
    theme_void()+
    theme(legend.title = element_text(face="bold",size=14))+
    theme(legend.text=element_text(size=14))

我看不到您的數據c的結構,因此我首先為sioux和des moines生成了long / lat並添加了geom_text元素:

假設您將圖定義為p,

  cit = data.frame(long=c(42.5,41.6),
             lat=c(-96.4,-93.6),
             label=c("sioux","des moines"))

  p + geom_text(aes(x = lat, y = long, label = label),
        data= cit,
        alpha = 1,
        color = "black",
        size = 4) # check size

或者,您可以在c中選擇那些直接提供城市的長/短線的線

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM