楼主: oliyiyi
2879 2

ggplot2 2.0.0.0 [推广有奖]

版主

已卖:2994份资源

泰斗

1%

还不是VIP/贵宾

-

TA的文库  其他...

计量文库

威望
7
论坛币
84105 个
通用积分
31671.0967
学术水平
1454 点
热心指数
1573 点
信用等级
1364 点
经验
384134 点
帖子
9629
精华
66
在线时间
5508 小时
注册时间
2007-5-21
最后登录
2025-7-8

初级学术勋章 初级热心勋章 初级信用勋章 中级信用勋章 中级学术勋章 中级热心勋章 高级热心勋章 高级学术勋章 高级信用勋章 特级热心勋章 特级学术勋章 特级信用勋章

楼主
oliyiyi 发表于 2015-12-26 08:32:02 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
December 22, 2015
By hadleywickham





[url=]inShare[/url]188





(This article was first published on RStudio Blog, and kindly contributed to R-bloggers)

I’m very pleased to announce the release of ggplot2 2.0.0. I know I promised that there wouldn’t be any more updates, but while working on the 2nd edition of the ggplot2 book, I just couldn’t stop myself from fixing some long standing problems.
On the scale of ggplot2 releases, this one is huge with over one hundred fixes and improvements. This might break some of your existing code (although I’ve tried to minimise breakage as much as possible), but I hope the new features make up for any short term hassle. This blog post documents the most important changes:
  • ggplot2 now has an official extension mechanism.
  • There are a handful of new geoms, and updates to existing geoms.
  • The default appearance has been thoroughly tweaked so most plots should look better.
  • Facets have a much richer set of labelling options.
  • The documentation has been overhauled to be more helpful, and require less integration across multiple pages.
  • A number of older and less used features have been deprecated.
These are described in more detail below. See the release notes for a complete list of all changes.
ExtensibilityPerhaps the bigggest news in this release is that ggplot2 now has an official extension mechanism. This means that others can now easily create their on stats, geoms and positions, and provide them in other packages. This should allow the ggplot2 community to flourish, even as less development work happens in ggplot2 itself. See vignette("extending-ggplot2") for details.
Coupled with this change, ggplot2 no longer uses proto or reference classes. Instead, we now use ggproto, a new OO system designed specifically for ggplot2. Unlike proto and RC, ggproto supports clean cross-package inheritance, which is necessary for extensibility. Creating a new OO system isn’t usually the right solution, but I’m pretty sure it was necessary here. Read more about it in the vignette.

New and updated geoms
  • ggplot no longer throws an error if you your plot has no layers. Instead it automatically adds geom_blank():ggplot(mpg, aes(cyl, hwy))
  • geom_count() (a new alias for the old stat_sum()) counts the number of points at unique locations on a scatterplot, and maps the size of the point to the count:ggplot(mpg, aes(cty, hwy)) +   geom_point()ggplot(mpg, aes(cty, hwy)) +  geom_count()
  • geom_curve() draws curved lines in the same way thatgeom_segment() draws straight lines:df <- expand.grid(x = 1:2, y = 1:2)ggplot(df, aes(x, y, xend = x + 0.5, yend = y + 0.5)) +  geom_curve(aes(colour = "curve")) +  geom_segment(aes(colour = "segment"))
  • geom_bar() now behaves differently from geom_histogram(). Instead of binning the data, it counts the number of unique observations at each location:ggplot(mpg, aes(cyl)) +   geom_bar()ggplot(mpg, aes(cyl)) +   geom_histogram(binwidth = 1)





二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:ggplot2 gplot plot GPL Improvements published releases article

缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

沙发
oliyiyi 发表于 2015-12-26 08:32:26
  • If you got into the (bad) habit of using geom_histogram() to create bar charts, or geom_bar() to create histograms, you’ll need to switch.
  • Layers are now much stricter about their arguments – you will get an error if you’ve supplied an argument that isn’t an aesthetic or a parameter. This breaks the handful of geoms/stats that used ... to pass additional arguments on to the underlying computation. Nowgeom_smooth()/stat_smooth() andgeom_quantile()/stat_quantile() use method.args instead; andstat_summary(), stat_summary_hex(), and stat_summary2d()use fun.args. This is likely to cause some short-term pain but in the long-term it will make it much easier to spot spelling mistakes and other errors.
  • geom_text() has been overhauled to make labelling your data a little easier. You can use nudge_x and nudge_y arguments to offset labels from their corresponding points.check_overlap = TRUE provides a simple way to avoid overplotting of labels: labels that would otherwise overlap are omitted.ggplot(mtcars, aes(wt, mpg, label = rownames(mtcars))) +  geom_point() +   geom_text(nudge_y = 0.5, check_overlap = TRUE)
    (Labelling points well is still a huge pain, but at least these new features make life a lit better.)
  • geom_label() works like geom_text() but draws a rounded rectangle underneath each label:grid <- expand.grid(  x = seq(-pi, pi, length = 50),  y = seq(-pi, pi, length = 50)) %>% mutate(r = x ^ 2 + y ^ 2, z = cos(r ^ 2) * exp(-r / 6))ggplot(grid, aes(x, y)) +  geom_raster(aes(fill = z)) +  geom_label(data = data.frame(x = 0, y = 0), label = "Center") +  theme(legend.position = "none") +  coord_fixed()
  • aes_() replaces aes_q(), and works like the SE functions in dplyr and my other recent packages. It supports formulas, so the most concise SE version of aes(carat, price) is nowaes_(~carat, ~price). You may want to use this form in packages, as it will avoid spurious R CMD check warnings about undefined global variables.ggplot(mpg, aes_(~displ, ~cty)) +   geom_point()# Same asggplot(mpg, aes(displ, cty)) +   geom_point()

AppearanceI’ve made a number of small tweaks to the default appearance:
  • The default theme_grey() background colour has been changed from “grey90” to “grey92”: this makes the background a little less visually prominent.
  • Labels and titles have been tweaked for readability. Axis labels are darker, and legend titles get the same visual treatment as axis labels.
  • The default font size dropped from 12 to 11. You might be surprised that I’ve made the default text size smaller as it was already hard for many people to read. It turns out there was a bug in RStudio (fixed in 0.99.724), that shrunk the text of all grid based graphics. Once that was resolved the defaults seemed too big to my eyes.
  • scale_size() now maps values to area, not radius. Usescale_radius() if you want the old behaviour (not recommended, except perhaps for lines). Continue to usescale_size_area() if you want 0 values to have 0 area.
  • Bar and rectangle legends no longer get a diagonal line. Instead, the border has been tweaked to make it visible, and more closely match the size of line drawn on the plot.ggplot(mpg, aes(factor(cyl), fill = drv)) +    geom_bar(colour = "black", size = 1) +   coord_flip()
  • geom_point() now uses shape 19 instead of 16. This looks much better on the default Linux graphics device. (It’s very slightly smaller than the old point, but it shouldn’t affect any graphics significantly). You can now control the width of the outline on shapes 21-25 with the stroke parameter.
  • The default legend will now allocate multiple rows (if vertical) or columns (if horizontal) in order to make a legend that is more likely to fit on the screen. You can override with thenrow/ncol arguments to guide_legend()p <- ggplot(mpg, aes(displ,hwy, colour = manufacturer)) +  geom_point() +   theme(legend.position = "bottom")p# Revert back to previous behaviourp + guides(colour = guide_legend(nrow = 1))
  • Two new themes were contributed by Jean-Olivier Irisson:theme_void() is completely empty and theme_dark() has a dark background designed to make colours pop out.

Facet labels

Thanks to the work of Lionel Henry, facet labels have received three major improvements:

  • You can switch the position of facet labels so they’re next to the axes.
  • facet_wrap() now supports custom labellers.
  • You can create combined labels when facetting by multiple variables.
Switching the labelsThe new switch argument allows you to switch the labels to display near the axes:
data <- transform(mtcars,  am = factor(am, levels = 0:1, c("Automatic", "Manual")),  gear = factor(gear, levels = 3:5, labels = c("Three", "Four", "Five")))ggplot(data, aes(mpg, disp)) +  geom_point() +  facet_grid(am ~ gear, switch = "both")
This is especially useful when the labels directly characterise the axes. In that situation, switching the labels can make the plot clearer and more readable. You may also want to use a neutral label background by setting strip.background to element_blank():
data <- mtcars %>%   mutate(    Logarithmic = log(mpg),    Inverse = 1 / mpg,    Cubic = mpg ^ 3,    Original = mpg) %>% tidyr::gather(transformation, mpg2, Logarithmic:Original)ggplot(data, aes(mpg2, disp)) +  geom_point() +  facet_wrap(~transformation, scales = "free", switch = "x") +  theme(strip.background = element_blank())





缺少币币的网友请访问有奖回帖集合
https://bbs.pinggu.org/thread-3990750-1-1.html

藤椅
minixi 发表于 2015-12-26 10:05:05
谢谢分享

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2025-12-30 01:00