技术控

    今日:0| 主题:63445
收藏本版 (1)
最新软件应用技术尽在掌握

[其他] ggplot2 2.2.0 coming soon!

[复制链接]
い明 媚 发表于 2016-10-1 12:41:00
246 3
I’m planning to release ggplot2 2.2.0 in early November. In preparation, I’d like to announce that a release candidate is now available: version 2.1.0.9001. Please try it out, and file an issue on GitHub if you discover any problems. I hope we can find and fix any major issues before the official release.
  Install the pre-release version with:
  1. # install.packages("devtools")
  2. devtools::install_github("hadley/ggplot2")
复制代码
  If you discover a major bug that breaks your plots, please file a minimal reprex , and then roll back to the released version with:
  1. install.packages("ggplot2")
复制代码
ggplot2 2.2.0 will be a relatively major release including:
  
       
  • Subtitles and captions.   
  • A large rewrite of the facetting system.   
  • Improved theme options.   
  • Better stacking   
  • Numerous bug fixes and minor improvements .  
   The majority of this work was carried out by Thomas Pederson , who I was lucky to have as my “ggplot2 intern” this summer. Make sure to check out other visualisation packages:  ggraph ,  ggforce , and  tweenr .
     Subtitles and captions

    Thanks to Bob Rudis , you can now add subtitles and captions:
  
  1. ggplot(mpg, aes(displ, hwy)) +
  2.   geom_point(aes(color = class)) +
  3.   geom_smooth(se = FALSE, method = "loess") +
  4.   labs(
  5.     title = "Fuel efficiency generally decreases with engine size",
  6.     subtitle = "Two seaters (sports cars) are an exception because of their light weight",
  7.     caption = "Data from fueleconomy.gov"
  8.   )
  9. unnamed-chunk-3-1

    unnamed-chunk-3-1
复制代码
   These are controlled by the theme settings plot.subtitle and  plot.caption .
    The plot title is now aligned to the left by default. To return to the previous centering, use theme(plot.title = element_text(hjust = 0.5)) .
       Facets

    The facet and layout implementation has been moved to ggproto and received a large rewrite and refactoring. This will allow others to create their own facetting systems, as descrbied in the Extending ggplot2 vignette. Along with the rewrite a number of features and improvements has been added, most notably:
   
       
  • Functions in facetting formulas, thanks to  Dan Ruderman .
    1. ggplot(diamonds, aes(carat, price)) +
    2.   geom_hex(bins = 20) +
    3.   facet_wrap(~cut_number(depth, 6))
    4. unnamed-chunk-4-1

      unnamed-chunk-4-1
    复制代码
       
  • Axes were dropped when the panels in  facet_wrap()  did not completely fill the rectangle. Now, an axis is drawn underneath the hanging panels:
    1. ggplot(mpg, aes(displ, hwy)) +
    2.   geom_point() +
    3.   facet_wrap(~class)
    复制代码

    ggplot2 2.2.0 coming soon!

    ggplot2 2.2.0 coming soon!

       
  • It is now possible to set the position of the axes through the  position  argument in the scale constructor:
    1. ggplot(mpg, aes(displ, hwy)) +
    2.   geom_point() +
    3.   scale_x_continuous(position = "top") +
    4.   scale_y_continuous(position = "right")
    复制代码

    ggplot2 2.2.0 coming soon!

    ggplot2 2.2.0 coming soon!

       
  • You can display a secondary axis that is a one-to-one transformation of the primary axis with the  sec.axis  argument:
    1. ggplot(mpg, aes(displ, hwy)) +
    2.   geom_point() +
    3.   scale_y_continuous(
    4.     "mpg (US)",
    5.     sec.axis = sec_axis(~ . * 1.20, name = "mpg (UK)")
    6.   )
    复制代码

    ggplot2 2.2.0 coming soon!

    ggplot2 2.2.0 coming soon!

       
  • Strips can be placed on any side, and the placement with respect to axes can be controlled with the  strip.placement  theme option.
    1. ggplot(mpg, aes(displ, hwy)) +
    2.   geom_point() +
    3.   facet_wrap(~ drv, strip.position = "bottom") +
    4.   theme(
    5.     strip.placement = "outside",
    6.     strip.background = element_blank(),
    7.     strip.text = element_text(face = "bold")
    8.   ) +
    9.   xlab(NULL)
    复制代码

    ggplot2 2.2.0 coming soon!

    ggplot2 2.2.0 coming soon!

       
       Theming

   
       
  • Blank elements can now be overridden again so you get the expected behavior when setting e.g.  axis.line.x .   
  • element_line()  gets an  arrow  argument that lets you put arrows on axes.
    1. arrow <- arrow(length = unit(0.4, "cm"), type = "closed")
    2. ggplot(mpg, aes(displ, hwy)) +
    3.   geom_point() +
    4.   theme_minimal() +
    5.   theme(
    6.     axis.line = element_line(arrow = arrow)
    7.   )
    复制代码

    ggplot2 2.2.0 coming soon!

    ggplot2 2.2.0 coming soon!

       
  • Control of legend styling has been improved. The whole legend area can be aligned according to the plot area and a box can be drawn around all legends:
    1. ggplot(mpg, aes(displ, hwy, shape = drv, colour = fl)) +
    2.   geom_point() +
    3.   theme(
    4.     legend.justification = "top",
    5.     legend.box.margin = margin(3, 3, 3, 3, "mm"),
    6.     legend.box.background = element_rect(colour = "grey50")
    7.   )
    复制代码

    ggplot2 2.2.0 coming soon!

    ggplot2 2.2.0 coming soon!

       
  • panel.margin  and  legend.margin  have been renamed to  panel.spacing  and  legend.spacing  respectively as this better indicates their roles. A new  legend.margin  has been actually controls the margin around each legend.   
  • When computing the height of titles ggplot2, now inclues the height of the descenders (i.e. the bits  g  and  y  that hang underneath). This makes improves the margins around titles, particularly the y axis label. I have also very slightly increased the inner margins of axis titles, and removed the outer margins.   
  • The default themes has been tweaked by  Jean-Olivier Irisson  making them better match  theme_grey() .   
  • Lastly, the  theme()  function now has named arguments so autocomplete and documentation suggestions are vastly improved.   
       Stacking bars

    position_stack() and  position_fill() now stack values in the reverse order of the grouping, which makes the default stack order match the legend.
  
  1. install.packages("ggplot2")0
复制代码
   

ggplot2 2.2.0 coming soon!

ggplot2 2.2.0 coming soon!

    (Note also the new geom_col() which is short-hand for  geom_bar(stat = "identity") , contributed by Bob Rudis.)
   Additionally, you can now stack negative values:
  
  1. install.packages("ggplot2")1
复制代码
   

ggplot2 2.2.0 coming soon!

ggplot2 2.2.0 coming soon!

   The overall ordering cannot necessarily be matched in the presence of negative values, but the ordering on either side of the x-axis will match.
    If you want to stack in the opposite order, try  forcats::fct_rev()  :
  
  1. install.packages("ggplot2")2
复制代码

unnamed-chunk-13-1

unnamed-chunk-13-1
tmddl 发表于 2016-10-20 13:07:13
传说中的沙发???哇卡卡
回复 支持 反对

使用道具 举报

羊威力 发表于 2016-11-17 15:56:44
羊威力天天灌水,好内疚!
回复 支持 反对

使用道具 举报

小猪在雨天 发表于 2016-11-21 11:57:34
い明 媚是我最崇拜的人!
回复 支持 反对

使用道具 举报

我要投稿

推荐阅读


回页顶回复上一篇下一篇回列表
手机版/c.CoLaBug.com ( 粤ICP备05003221号 | 粤公网安备 44010402000842号 )

© 2001-2017 Comsenz Inc.

返回顶部 返回列表