好消息,ggplot2更新了。有了新的提升,改进了一些小错误。减少了对一些包的依赖,且保持足够精简。
There are also a range of smaller features in this release that may not be earth shattering, but could mean the world to some
下面就是一些简单的介绍,
ggplot2 3.3.0版本是昨天更新的,emmm,我看了官方的教程发布说明,感觉我还是看不懂,英语不熟悉,一些ggplot2的专有术语。
从我个人而言,这次更新关于地理填充的那个对我有用。之前就是画出来就是这样的,我还以为是数据问题,没想到是函数问题。这次好像是更新了。
![5934c3c07cf957a707f5bfb0e720a230.png](https://img-blog.csdnimg.cn/img_convert/5934c3c07cf957a707f5bfb0e720a230.png)
![f07025657173d01a85599f86c5344235.png](https://img-blog.csdnimg.cn/img_convert/f07025657173d01a85599f86c5344235.png)
对我而言还有一个就是画水平的条形图不用再旋转坐标了,可以直接生成。这次确实很方便
![3f433260033ecd42fc3d6ffe73bf4e71.png](https://img-blog.csdnimg.cn/img_convert/3f433260033ecd42fc3d6ffe73bf4e71.png)
![41899943af2e7bcb4761cb82f951e4ff.png](https://img-blog.csdnimg.cn/img_convert/41899943af2e7bcb4761cb82f951e4ff.png)
这次还有更新一些东西,我不太能看得懂,我也不经常用到。
大神可以看Rstudio的blog:
ggplot2 3.3.0 - Tidyversewww.tidyverse.org![7566642104d389650e1a2cc0b6082510.png](https://img-blog.csdnimg.cn/img_convert/7566642104d389650e1a2cc0b6082510.png)
如果是小白,我建议还是不要看了,因为我感觉用处不大,
下面都是屁话(可以图个乐)
重新写了坐标轴代码
library(ggplot2)
p <- ggplot(mpg) +
geom_bar(aes(x = manufacturer)) +
theme(axis.text.x = element_text(size = 11))
# Overlapping labels
plot(p)
![46e3a630be81daf9e790050f1b9aedd0.png](https://img-blog.csdnimg.cn/img_convert/46e3a630be81daf9e790050f1b9aedd0.png)
# Use guide_axis to dodge the labels
p +
scale_x_discrete(guide = guide_axis(n.dodge = 2))
![0a266c0a0a8d5808e0ea4cab764f471c.png](https://img-blog.csdnimg.cn/img_convert/0a266c0a0a8d5808e0ea4cab764f471c.png)
# Or to remove overlapping labels
p +
scale_x_discrete(guide = guide_axis(check.overlap = TRUE))
![72ed0c7b62d58e8486e4ce2b6ef354b3.png](https://img-blog.csdnimg.cn/img_convert/72ed0c7b62d58e8486e4ce2b6ef354b3.png)
加入了新的图例
以前离散的数据只能用离散型的图例函数,现在不用管了。
p <- ggplot(mpg) +
geom_point(aes(displ, cty, size = hwy, colour = hwy))
p +
scale_size_binned()
![405cf940e4c0a4b5b97b5e1f6782ee92.png](https://img-blog.csdnimg.cn/img_convert/405cf940e4c0a4b5b97b5e1f6782ee92.png)
p +
scale_colour_binned()
![0c8979d133d35100e900e4f5a31e0ad4.png](https://img-blog.csdnimg.cn/img_convert/0c8979d133d35100e900e4f5a31e0ad4.png)
p +
scale_size_binned(guide = guide_bins(show.limits = TRUE))
![2ae568a84d542f81f2b7bbb1c9b4f2f9.png](https://img-blog.csdnimg.cn/img_convert/2ae568a84d542f81f2b7bbb1c9b4f2f9.png)
p +
scale_x_binned()
![b13321791911c5e3253b5111f8e422f6.png](https://img-blog.csdnimg.cn/img_convert/b13321791911c5e3253b5111f8e422f6.png)
ggplot(mpg) +
geom_bar(aes(displ)) +
scale_x_binned()
![2f670a564fc57263abaeb9d26f97d4e8.png](https://img-blog.csdnimg.cn/img_convert/2f670a564fc57263abaeb9d26f97d4e8.png)
画水平的条形图不需要之前那么麻烦了
以前的代码
ggplot(mpg) +
geom_bar(aes(x = manufacturer)) +
coord_flip()
![3f433260033ecd42fc3d6ffe73bf4e71.png](https://img-blog.csdnimg.cn/img_convert/3f433260033ecd42fc3d6ffe73bf4e71.png)
新版本里面:
ggplot(mpg) +
geom_bar(aes(y = manufacturer))
![3f433260033ecd42fc3d6ffe73bf4e71.png](https://img-blog.csdnimg.cn/img_convert/3f433260033ecd42fc3d6ffe73bf4e71.png)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth(orientation = "y")
![41899943af2e7bcb4761cb82f951e4ff.png](https://img-blog.csdnimg.cn/img_convert/41899943af2e7bcb4761cb82f951e4ff.png)
画轮廓图
以前的错误代码:
volcano_long <- data.frame(
x = as.vector(col(volcano)),
y = as.vector(row(volcano)),
z = as.vector(volcano)
)
ggplot(volcano_long, aes(x, y, z = z)) +
geom_polygon(aes(fill = stat(level)), alpha = 0.5, stat = "contour") +
guides(fill = "legend")
![5934c3c07cf957a707f5bfb0e720a230.png](https://img-blog.csdnimg.cn/img_convert/5934c3c07cf957a707f5bfb0e720a230.png)
现在改进的代码:
ggplot(volcano_long, aes(x, y, z = z)) +
geom_contour_filled(aes(fill = stat(level)), alpha = 0.5)
![f07025657173d01a85599f86c5344235.png](https://img-blog.csdnimg.cn/img_convert/f07025657173d01a85599f86c5344235.png)
ggplot(volcano_long, aes(x, y, z = z)) +
geom_contour_filled(aes(fill = stat(level))) +
guides(fill = guide_colorsteps(barheight = unit(10, "cm")))
![a45010801d178f0cc403517b849a5138.png](https://img-blog.csdnimg.cn/img_convert/a45010801d178f0cc403517b849a5138.png)