ggplot2中的geom_text vs theme(element_text)v2:未知参数:face

时间:2015-12-22 20:38:03

标签: r ggplot2

这个例子很好用:

library(ggplot2)
ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar() +
      theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
            panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
            legend.title = element_text(size=12, face="bold"),
            axis.title.x=element_text(face="bold", vjust=0.1),
            axis.title.y=element_text(face="bold", vjust=0.4)) 

在我自己的情节中,"面对"参数有问题:

ggplot()+
  #geom_point(data=sitescores2, aes(x=rda1, y=rda2, color=Dates), shape=17)+
  geom_segment(data=biplotscores2, aes(x=0, y=0, xend=rda1, yend=rda2), arrow=arrow(length=unit(0.2,"cm")), alpha=0.75, color="black") +
  geom_text(data=biplotscores2, aes(x=1.1*rda1, y=1.1*rda2,label=rownames(biplotscores2)), size=3, color="black", face="bold")+
  #xlab("rda1   (45.7% explained variance)")+
  #ylab("rda2   (19.3% explained variance)")+
  #annotate ("text", x = 0.5, y = -0.75, label = "Constrained Inertia 20.3%") +
  theme_bw()+
  theme(panel.border = element_blank(), panel.grid.major = element_blank(), 
        panel.grid.minor = element_blank(), axis.line = element_line(colour = "black"),
        legend.title = element_text(size=12, face="bold"),
        axis.title.x=element_text(face="bold", vjust=0.1),
        axis.title.y=element_text(face="bold", vjust=0.4)) +
  guides(color = guide_legend(override.aes = list(size=4)))

每当geom_text()行没有被注释掉时,我就会

Error: Unknown parameters: face

 sessionInfo()
    R version 3.2.3 (2015-12-10)
    Platform: x86_64-w64-mingw32/x64 (64-bit)
    Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252   
[3] LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
[5] LC_TIME=German_Germany.1252    

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] reshape2_1.4.1    adegraphics_1.0-4 gridExtra_2.0.0   broom_0.4.0      
 [5] ggplot2_2.0.0     GGally_1.0.0      ape_3.4           PCNM_2.1-2       
 [9] packfor_0.0-8     MASS_7.3-45       AEM_0.5-2         boot_1.3-17      
[13] spdep_0.5-92      Matrix_1.2-3      sp_1.2-1          ade4_1.7-3       
[17] vegan_2.3-2       lattice_0.20-33   permute_0.8-4    

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.2        RColorBrewer_1.1-2 plyr_1.8.3         LearnBayes_2.15   
 [5] tools_3.2.3        digest_0.6.8       gtable_0.1.2       nlme_3.1-122      
 [9] mgcv_1.8-10        psych_1.5.8        DBI_0.3.1          parallel_3.2.3    
[13] coda_0.18-1        stringr_1.0.0      dplyr_0.4.3        cluster_2.0.3     
[17] reshape_0.8.5      R6_2.1.1           tidyr_0.3.1        deldir_0.1-9      
[21] magrittr_1.5       scales_0.3.0       splines_3.2.3      mnormt_1.5-3      
[25] assertthat_0.1     colorspace_1.2-6   labeling_0.3       KernSmooth_2.23-15
[29] stringi_1.0-1      munsell_0.4.2     

 dput(biplotscores2)
    structure(list(rda1 = c(-0.0638545017927902, -0.0790948107365942, 
    0.253839469241586, -0.654873079658184, -0.123346871475591, 0.026444542624931, 
    -0.39244699736642, 0.0813548717740846, -0.27583341679788, -0.496210550125183, 
    -0.238647767212786), rda2 = c(-0.662452722771145, -0.481117095416355, 
    -0.066373295719382, 0.199066523847874, 0.117559433772518, -0.51481582100134, 
    -0.00547351784681829, -0.170265606276408, 0.0753076387127382, 
    -0.115174075680816, -0.039200942054552)), .Names = c("rda1", 
    "rda2"), row.names = c("Soil_Moisture", "Bulk_density", "Clay_pct", 
    "pH", "N_pct", "NH4", "PO4", "EOC", "C_mic", "N_mic", "PLFA_total"
    ), class = "data.frame")

你有什么想法,最新版本的ggplot2有什么变化吗?

1 个答案:

答案 0 :(得分:4)

我认为geom_text中的审美实际上称为fontface,而不是face,即使在element_text中它只被称为face。我认为这只是一个命名不一致。

根据this Github提交,geom_text美学已被称为fontface很长一段时间了。