數(shù)據(jù)及基礎(chǔ)圖形的繪制
1、數(shù)據(jù)——以R自帶數(shù)據(jù)集iris為例
df<-iris
2恶复、基于ggplot2包繪制散點圖
#加載繪圖包
library(ggplot2)
library(ggthemes)
#繪圖
p<-ggplot(df, aes(Sepal.Length, Sepal.Width, color = Species)) +
geom_point(size=4) +
theme_solarized()+
theme(legend.key = element_rect(fill = 'transparent'))
p
局部放大效果的實現(xiàn)
1、加載包——主要基于ggforce包實現(xiàn)圖形的局部放大
library(ggforce)
2齐遵、局部放大某一組的數(shù)據(jù)
p+facet_zoom(x = Species == "setosa")
p+facet_zoom(x = Species == "versicolor")
p+facet_zoom(x = Species == "virginica")
當(dāng)然寂玲,也可以將局部放大的圖展現(xiàn)在y軸上:
p+facet_zoom(y = Species == "versicolor")
3塔插、根據(jù)設(shè)置的閾值局部放大圖形
p+facet_zoom(x = Sepal.Length > 6)
p+facet_zoom(y = Sepal.Width > 3)
4梗摇、通過同時設(shè)置x和y的范圍實現(xiàn)圖中特定區(qū)域的放大
p+facet_zoom(xlim = c(5,6),ylim = c(2.5,3))
p+facet_zoom(xlim = c(5,6),ylim = c(2.5,3), split = T)
p+facet_zoom(xy = Species == "versicolor", split = T)
5、設(shè)置縮放面板與完整數(shù)據(jù)面板的相對大小,通過zoom.size控制想许,默認(rèn)值為2伶授,即縮放面板的大小是完整數(shù)據(jù)面板的兩倍
p+facet_zoom(xy = Species == "versicolor",split = T,
zoom.size = 1.5)
p+facet_zoom(xy = Species == "versicolor",split = T,
zoom.size = 3)