日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

ggplot2中显示坐标轴_R可视化11|ggplot2-图层图形语法 (3)

發(fā)布時間:2023/11/27 生活经验 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ggplot2中显示坐标轴_R可视化11|ggplot2-图层图形语法 (3) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文系統(tǒng)介紹ggplot2的統(tǒng)計變換(stat)、位置設(shè)置(Position adjustments)和標(biāo)度(scale)。

本文目錄

6、統(tǒng)計變換(stat)stats can be created with a geom_ functionstats can’t be created with a geom_ function7、 位置設(shè)置(Position adjustments)條形圖中stack|fill|dodge散點(diǎn)圖中nudge|jitter|jitterdodge8、標(biāo)度(scale)marker的形狀和大小圖例和坐標(biāo)軸

6、統(tǒng)計變換(stat

將data經(jīng)過一種統(tǒng)計方法整理,然后再繪圖,ggplot2的統(tǒng)計方法如下,都是以stat_開頭的函數(shù)。

可以分為兩類:

stats can be created with a geom_ function

  • stat_bin(): geom_bar(), geom_freqpoly(), geom_histogram()
  • stat_bin2d(): geom_bin2d()
  • stat_bindot(): geom_dotplot()
  • stat_binhex(): geom_hex()
  • stat_boxplot(): geom_boxplot()
  • stat_contour(): geom_contour()
  • stat_quantile(): geom_quantile()
  • stat_smooth(): geom_smooth()
  • stat_sum(): geom_count()
options(repr.plot.width = 4.5, repr.plot.height = 3, repr.plot.res = 300)
f <- ggplot(mpg, aes(class, hwy))
f + geom_boxplot() 

stats can’t be created with a geom_ function

  • stat_ecdf(): compute a empirical cumulative distribution plot.
  • stat_function(): compute y values from a function of x values.
  • stat_summary(): summarise y values at distinct x values.
  • stat_summary2d(), stat_summary_hex(): summarise binned values.
  • stat_qq(): perform calculations for a quantile-quantile plot.
  • stat_spoke(): convert angle and radius to position.
  • stat_unique(): remove duplicated rows.
ggplot(mpg, aes(trans, cty)) + geom_point() + stat_summary(geom = "point", fun = "mean", colour = "red", size = 4)


7、 位置設(shè)置(Position adjustments)

  • 條形圖中stack|fill|dodge
  • position_stack(): stack overlapping bars (or areas) on top of each other.
  • position_fill(): stack overlapping bars, scaling so the top is always at 1.
  • position_dodge(): place overlapping bars (or boxplots) side-by-side.
options(repr.plot.width = 4.5, repr.plot.height = 5, repr.plot.res = 300)
dplot <- ggplot(diamonds, aes(color, fill = cut)) + xlab(NULL) + ylab(NULL) + theme(legend.position = "none")p1 <- dplot + geom_bar()#默認(rèn)堆疊
p2 <- dplot + geom_bar(position = "fill")#堆疊且按比例
p3 <- dplot + geom_bar(position = "dodge")#并列p4 <- grid.arrange(p1,p2,p3,nrow = 3)
ggsave("scale23.png", p4, width = 4.5, height = 5) 

  • 散點(diǎn)圖中nudge|jitter|jitterdodge
  • position_nudge(): move points by a fixed offset.
  • position_jitter(): add a little random noise to every position.
  • position_jitterdodge(): dodge points within groups, then add a little random noise.
p1 <- ggplot(mpg, aes(displ, hwy)) + geom_point(position = "jitter")
p2 <- ggplot(mpg, aes(displ, hwy)) + geom_point(position = position_jitter(width = 0.05, height = 0.5))
p3 <- ggplot(mpg, aes(displ, hwy)) + geom_jitter(width = 0.05, height = 0.5)p4 <- grid.arrange(p1,p2,p3,nrow = 3)
ggsave("scale24.png", p4, width = 4.5, height = 5) 


8、標(biāo)度(scale

這部分內(nèi)容,這里介紹一些沒提到的,前面寫已過三篇文章詳細(xì)介紹:

R可視化06|ggplot2圖層-標(biāo)度圖層(scale layer)-坐標(biāo)軸篇
R可視化07|ggplot2圖層-標(biāo)度圖層(scale layer)-顏色盤篇
R可視化08|ggplot2圖層-標(biāo)度圖層(scale layer)-圖例篇
  • marker的形狀和大小

使用第一行的數(shù)字即可使用第二行的形狀。

options(repr.plot.width = 6.5, repr.plot.height = 5, repr.plot.res = 300)#marker形狀
p <- e + geom_point(aes(shape = fl, size = cyl))p1 <- p + scale_shape() + scale_size() 
p2 <- p + scale_shape_manual(values = c(1:26))#values = c(1:26)指定marker#marker大小
p3 <- p + scale_radius(range = c(1,6))
p4 <- p + scale_size_area(max_size = 6)
p5 <- grid.arrange(p2,p3,p4,nrow = 2)
ggsave("scale25.png", p5, width = 4.5, height = 5) 

  • 圖例和坐標(biāo)軸


本文結(jié)束,更多好文,歡迎關(guān)注公眾號:pythonic生物人

Python可視化|Matplotlib39-Matplotlib 1.4W+字教程(珍藏版)
Python可視化|Matplotlib&Seaborn36(完結(jié)篇)
python3基礎(chǔ)12詳解模塊和包(庫)|構(gòu)建|使用
Perl基礎(chǔ)系列合集
NGS各種組學(xué)建庫原理(圖解)

總結(jié)

以上是生活随笔為你收集整理的ggplot2中显示坐标轴_R可视化11|ggplot2-图层图形语法 (3)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。