这个功能今天工作得时候需要,就搜了一下,有个 ggforce 包可以做这个事情(之前还 mark 过,哈哈)。
简单用示例代码展示如何使用它,主要是根据数据得选择进行放大或者根据坐标范围进行放大。
安装:
install.packages("ggforce")
加载:
library(ggforce)
先看一个正常得图:
ggplot(iris,aes(Petal.Length,Petal.Width,colour=Species))+geom_point()
我们取一个分类得数据进行放大:
ggplot(iris,aes(Petal.Length,Petal.Width,colour=Species))+geom_point()+facet_zoom(x=Species=='versicolor')
突然之间就有点逼格了,如果再配上个主题,再好不过了。
学术版本:
ggplot(iris,aes(Petal.Length,Petal.Width,colour=Species))+geom_point()+facet_zoom(x=Species=='versicolor')+cowplot::theme_cowplot()
娱乐版本:
ggplot(iris,aes(Petal.Length,Petal.Width,colour=Species))+geom_point()+facet_zoom(x=Species=='versicolor')+theme_dark()
还可以选择性展示数据:
ggplot(iris,aes(Petal.Length,Petal.Width,colour=Species))+geom_point()+facet_zoom(x=Species=='versicolor',zoom.data=Species=='versicolor')+cowplot::theme_cowplot()
再蕞后看下怎么按坐标范围放大吧:
ggplot(iris,aes(Petal.Length,Petal.Width,colour=Species))+geom_point()+facet_zoom(xlim=c(2,4))+cowplot::theme_cowplot()
更多学习见包文档:感谢分享ggforce.data-imaginist感谢原创分享者/[1]
参考资料[1]
感谢分享ggforce.data-imaginist感谢原创分享者/: 感谢分享ggforce.data-imaginist感谢原创分享者/