无法在ggplot2中绘制带有标题的散点图

时间:2016-05-06 12:20:29

标签: r plot ggplot2

尝试从https://rpubs.com/juliasilge/178458

重现该情节

创建数据框:

library(dplyr)
pingpongDF <- data_frame(quarters = c("3Q 2014", "4Q 2014", "1Q 2015", "2Q 2015", "3Q 2015", 
          "4Q 2015", "1Q 2016"),
          pingpong = c(142, 230, 215, 190, 145, 153, 60),
          VCdeals = c(1012, 1015, 1001, 1100, 960, 920, 860))

library(ggplot2)
ggplot(pingpongDF, aes(x = pingpong, y = VCdeals, label = quarters)) +
    geom_point(color = "white", size = 7) +
    geom_vline(xintercept = 150, color = "white", size = 1.5) +
    geom_hline(yintercept = 1000, color = "white", size = 1.5) +
    geom_text(check_overlap = TRUE, color = "gray60", family="Roboto-Bold", vjust = 0, nudge_y = 10, nudge_x = -5) +
    annotate("text", label = "In the most\nrecent quarter\nboth measures\nwere low.", family="Roboto-Bold",
             color = "black", x = 70, y = 868, hjust = 0, size = 4) +
    labs(title = "Tech Bounce",
         subtitle = "Sales of ping-pong tables to companies at a Silicon Valley store\ncorrelate with venture-capital deals made during the same quarter",
         y = "Venture-capital deals made", 
         x = "Ping-pong tables sold",
         caption = "Sources: Billiard Wholesale (sales), Dow Jones VentureSource (deals)") +
    xlim(50, 250) + ylim(850, 1150) +
    theme_minimal(base_family = "RobotoCondensed-Regular", base_size = 14) +
    theme(plot.title=element_text(family="Roboto-Bold")) +
    theme(panel.background = element_rect(fill = "#CBDEB1")) +
    theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank()) +
    theme(plot.caption=element_text(size=9)) +
    theme(plot.caption=element_text(margin=margin(t=10)))

我应该得到这个图:

enter image description here

但是在编写Rstudio中的代码时,我最终得到了这个错误:

Error in (function (el, elname)  : 
"plot.caption" is not a valid theme element name.
Calls: <Anonymous> ... withVisible -> eval -> eval -> theme -> mapply ->             <Anonymous>
Execution halted

需要帮助,因为我想为我创建的情节添加标题.....但它似乎无法正常工作....已将软件包更新到最新版本....

sessionInfo()
R version 3.3.0 (2016-05-03)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

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

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

other attached packages:
[1] ggplot2_2.1.0

loaded via a namespace (and not attached):
[1] colorspace_1.2-6 scales_0.4.0     plyr_1.8.3       rsconnect_0.4.3 
[5] htmltools_0.3.5  tools_3.3.0      gtable_0.2.0     yaml_2.1.13     
[9] Rcpp_0.12.4      rmarkdown_0.9.6  grid_3.3.0       knitr_1.12.3    
[13] digest_0.6.9     munsell_0.4.3   

0 个答案:

没有答案