代码之家  ›  专栏  ›  技术社区  ›  Calflamesfann

在打印标题中混合不同的字体大小/字体

  •  0
  • Calflamesfann  · 技术社区  · 7 年前

    使用下面的代码在R中生成热图,效果很好。第一部分是我用来给地图上色的度量。我的问题是,我将如何阅读下面的标题。我知道在以caption=Paste(“Source…”)开头的部分中,一个会将第一行放在另一行的前面然而,如何让第一行变得更大,字体更粗体,这让我不知所措。

    Current Result

     map50<- merge(us50, pop1)
    
     breaks <- seq(-.01, .05, by = .01)
     map50$c1<- cut(map50$growth, breaks, label=c("-1% to 0%", "0% to 1%", "1% 
     to 2%", "2% to 3%", "3% to 4%","4% to 5%"))
    
    
    library(ggplot2)
    b= ggplot(data= map50, aes(x=long, y=lat, group=group))
    d= b+geom_polygon(aes(fill=c1), 
    colour=alpha("black"),size=.05)+scale_fill_brewer(palette="YlOrRd",name="y/y 
    growth rates")+coord_equal()
    d= d+labs(x = NULL, y = NULL, fill = NULL,
    title = "Average Employment Growth By State Q3 2018",
    subtitle = "For Private, All Industries",
    caption = paste("Source: BLS Quarterly Census of Employment and 
    Wages\nProduced By: @NVlabormarket"))
    d= d+theme_void()
    d=d+theme(text = element_text(family = "NimbusSan", size = 10),
    plot.title = element_text(size = 20, face = "bold"),
    plot.margin = unit(c(0, 0.25, 0.0, 0.25), "in"),
    panel.border = element_rect(fill = NA, colour = "#cccccc"),
    legend.text = element_text(size = 8),
    legend.position=c(.93, 0.2))
    ggsave("Q32018EmploymentGrowthHeat-YlOrRdu.pdf")
    
    1 回复  |  直到 7 年前
        1
  •  6
  •   pogibas    7 年前

    您可以使用 caption 参数和第二行使用 tag 争论 labs 作用接下来,您必须使用手动指定标记位置 plot.tag.position .

    library(ggplot2)
    ggplot(mtcars, aes(cyl, mpg)) + 
        geom_point() +
        labs(caption = "Source: BLS Quarterly Census of Employment and Wages",
             tag = "Produced By: @NVlabormarket") +
        theme(plot.caption = element_text(vjust = 4, size = 9, face = "bold"),
              plot.tag = element_text(size = 9),
              plot.tag.position = c(0.89, 0))
    

    enter image description here