在绘图标题中混合使用不同的字体大小/字体

时间:2019-03-13 20:13:41

标签: r ggplot2

使用下面的代码在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 个答案:

答案 0 :(得分:3)

您可以在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