箱式图 分组_小白学R(三):重复测量数据的箱式图上的p值如何改大小呢?
上一期分享了重復(fù)數(shù)據(jù)箱式圖的使用條件和數(shù)據(jù)格式小白學(xué)R(二):重復(fù)測(cè)量數(shù)據(jù)/連續(xù)數(shù)據(jù)的箱式圖(ggplot包)(1),今天就奉上箱式圖的代碼和以及如何改箱式圖上的p值大小。
畫(huà)箱式圖
1.1 先看數(shù)據(jù)表dt2,其中time是時(shí)間分組(w1, w2, w4, w8), value是具體數(shù)值, group是分組(contro組和intervention組)
?1.2 畫(huà)圖代碼如下:
png(filename = "boxplot.png",width=2600,height=2600,res=500) #設(shè)定導(dǎo)出圖片的格式為PNGggplot(data = dt2, aes(x = time, y = value,fill = group)) + geom_boxplot(outlier.colour = NA) + geom_dotplot(binaxis='y', stackdir='center', binwidth = 100, position = position_dodge(0.75))+ labs(fill = "group", x = "time", y = "Value") + scale_y_continuous(lim = c(0, 8000)) + theme_classic(base_size = 20) + theme(legend.position = c(0.9, 0.7))+ stat_compare_means(method = "wilcox.test",?????????????????????label?=?"p.format")dev.off()注:這里stat_compare_means是進(jìn)行兩兩比較,由于非正態(tài)分布,所以用wilcox.test,重復(fù)測(cè)量數(shù)據(jù)這樣比較的對(duì)錯(cuò)與否先不討論哈。
1.3 出圖:
2. 箱式圖改顏色,改圖例位置,改字體等都可以在help里搜相應(yīng)函數(shù),具體怎么改文檔里講解都很細(xì)致,但如果嫌圖上p值太小,想改大怎么辦呢?這個(gè)小白也是搜了很多論壇,發(fā)現(xiàn)解決方案不少,在此就選一個(gè)簡(jiǎn)介易懂分享給大家:
png(filename = "igg.png",width=2600,height=2600,res=500)your_font_size <- 5 # 改變box上p值大小的coreggplot(data = dt2, aes(x = time, y = value,fill = group)) +geom_boxplot(outlier.colour = NA) +geom_dotplot(binaxis='y', stackdir='center', binwidth = 100, position = position_dodge(0.75))+labs(fill = "group", x = "time", y = "Value") +scale_y_continuous(lim = c(0, 8000)) +theme_classic(base_size = 20) +theme(legend.position = c(0.9, 0.7))+stat_compare_means(method = "wilcox.test",label = "p.format", size = your_font_size)dev.off()代碼第2行:your_font_size 及第11行:size = your_font_size就是解決問(wèn)題的關(guān)鍵啦!
今天的內(nèi)容你學(xué)費(fèi)了嘛
喜歡請(qǐng)關(guān)注我呀!
總結(jié)
以上是生活随笔為你收集整理的箱式图 分组_小白学R(三):重复测量数据的箱式图上的p值如何改大小呢?的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 导入第三方组件_大型 web 应用公共组
- 下一篇: 求两个不超过200位的非负整数积_必看: