r - 用ggplot2绘制粗体字母?

标签 r

我正在使用 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

最佳答案

也许是 ggplot专家会知道这是否可以直接在 ggplot ,但由于 ggplot用途 grid你可以

require(grid)
grid.edit("geom_point.points", grep = TRUE, global=TRUE, gp = gpar(fontface="bold"))

在事后加粗字母。

关于r - 用ggplot2绘制粗体字母?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31993351/

相关文章:

r - 下一个出现的记录的索引

r - ggplot2:将颜色固定为因子水平

r - 使用 data.table 创建滞后列

r - ggplots 中的躲避 geom_point 用于呈现误差条的估计

python - R 中的 Collat​​z 猜想

R:根据其他列条件比较列中的元素?

r - 在 r 中的 dplyr::group_by 之后将组变量转换为组名称

r - 如何在一个图中绘制 'multiple box plots'?

r - 使用 ggplot 绘制月度数据

r - 将 ggplot2 geoms 添加到简单的特征图