使用ggplot2绘制粗体字母?

4
我正在使用ggplot2构建一个图形,其中包含四个绘图区域,每个区域都由特定的建模领域组成。我想用粗体字在以下图表中制作字母。使用符号太麻烦了,因为我有8个类别,而这些符号看起来太相似了。

Example plot

以下是一个可重现的示例。
数据:
Covariate.Weights.Data= structure(list(Species = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 
6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 
6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 
6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L), .Label = c("American black duck", 
"American wigeon", "Blue-winged teal", "Gadwall", "Green-winged teal", 
"Mallard", "Northern pintail", "Northern shoveler"), class = "factor"), 
    Flyway = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
    2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
    1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
    2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
    1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
    2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
    1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("Atlantic", 
    "Mississippi"), class = "factor"), Season = structure(c(1L, 
    1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 
    1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 
    2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 
    2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 
    1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 
    1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 
    2L, 1L, 1L, 2L, 2L), .Label = c("Fall", "Spring"), class = "factor"), 
    Covariates = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
    1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L), .Label = c("Forage", 
    "Habitat", "Survey"), class = "factor"), Weights = c(0.31, 
    1, 0, 0.96, 0, 0, 1, 0, 1, 1, 0, 0.06, 1, 1, 1, 0.06, 0, 
    1, 0.01, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0.82, 1, 1, 0.31, 
    0.43, 0, 0.82, 1, 1, 1, 0.92, 1, 0, 1, 0.97, 1, 1, 0, 0.94, 
    1, 1, 0.05, 0, 1, 1, 1, 1, 1, 1, 1, 0.07, 0.99, 1, 1, 1, 
    0.69, 0, 1, 0.04, 0, 0, 0, 0.08, 0, 0, 0, 0.02, 0, 0, 0, 
    0, 0, 0, 0.94, 0, 0, 0, 0, 0, 0, 0, 0, 0.93, 0.01, 0, 0, 
    0)), .Names = c("Species", "Flyway", "Season", "Covariates", 
"Weights"), class = "data.frame", row.names = c(NA, -96L))

情节:

require(ggplot2)    
Covariates.Weights.Plot = 
      ggplot(Covariate.Weights.Data, aes(x=Covariates,y=Weights,shape=Species)) +
      facet_grid(Flyway~Season) + ylab("Relative Importance") +
      geom_point(size=5, position=position_jitter(h=0.1,w=0.3)) +
      scale_shape_manual(values=LETTERS[c(1,23,2,7,20,13,16,19)]) + 
      theme(text=element_text(size=20, face="bold"), 
            axis.text.y=element_text(size=20),
            axis.text.x=element_text(size=20), 
            axis.title.y=element_text(size=30, face="bold", vjust=1),
            axis.title.x=element_text(size=30, face="bold", vjust=0),
            strip.text=element_text(size=30, colour="black", face="bold", 
                                    vjust=1))
    Covariates.Weights.Plot

3
以防您不知道:如果您正在使用geom_text(),则可以直接使用fontface="bold"参数来设置粗体字。 - maj
2个回答

7
也许一个熟练使用 ggplot 的专家会知道这是否可能直接在 ggplot 中实现,但是由于 ggplot 使用 grid,所以您可以...
require(grid)
grid.edit("geom_point.points", grep = TRUE, global=TRUE, gp = gpar(fontface="bold"))

要在事实之后加粗字母。

2

您可以在顶部绘制稍大的字母。为了使它们对齐(至少是更容易地),最好使用dodge。

  ggplot(...)+...+
    geom_point(size=5, position=position_dodge(width=.6)) +
    geom_point(size=5.8,position=position_dodge(width=.6))+
  ...

enter image description here


1
Dodge是一个很好的技巧,它已经显著地改善了图表的外观。 - Nigel Stackhouse

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接