亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ggplot2-抖動和位置閃避在一起

ggplot2-抖動和位置閃避在一起

慕仙森 2019-12-27 10:19:47
我正在嘗試從GGplot2研討會http://dl.dropbox.com/u/42707925/ggplot2/ggplot2slides.pdf重新創建一個圖形。在這種情況下,我試圖生成示例5,其中抖動的數據點容易閃避。當我運行代碼時,這些點圍繞正確的線居中,但沒有抖動。這是直接來自演示文稿的代碼。set.seed(12345)hillest<-c(rep(1.1,100*4*3)+rnorm(100*4*3,sd=0.2),       rep(1.9,100*4*3)+rnorm(100*4*3,sd=0.2))rep<-rep(1:100,4*3*2)process<-rep(rep(c("Process 1","Process 2","Process 3","Process 4"),each=100),3*2)memorypar<-rep(rep(c("0.1","0.2","0.3"),each=4*100),2)tailindex<-rep(c("1.1","1.9"),each=3*4*100)ex5<-data.frame(hillest=hillest,rep=rep,process=process,memorypar=memorypar, tailindex=tailindex)stat_sum_df <- function(fun, geom="crossbar", ...) {stat_summary(fun.data=fun, geom=geom, ...) }dodge <- position_dodge(width=0.9) p<- ggplot(ex5,aes(x=tailindex ,y=hillest,color=memorypar)) p<- p + facet_wrap(~process,nrow=2) + geom_jitter(position=dodge) +geom_boxplot(position=dodge)  p
查看完整描述

2 回答

?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

編輯:ggplot2使用1.0.0版有更好的解決方案position_jitterdodge。參見@Didzis Elferts的答案。請注意,這dodge.width控制了閃避jitter.width的寬度并控制了抖動的寬度。


我不確定代碼如何在pdf中產生圖形。


但是,這樣的事情會使您接近所追求的嗎?


我將tailindex和轉換memorypar為數字;將它們加在一起;結果是該geom_jitter圖層的x坐標??赡苡幸环N更有效的方法。另外,我想看看如何避開geom_boxplot和geom_jitter,并且沒有抖動,會在pdf中產生圖形。


library(ggplot2)

dodge <- position_dodge(width = 0.9)

ex5$memorypar2 <- as.numeric(ex5$tailindex) + 

  3 * (as.numeric(as.character(ex5$memorypar)) - 0.2) 


p <- ggplot(ex5,aes(x=tailindex , y=hillest)) +

   scale_x_discrete() +

   geom_jitter(aes(colour = memorypar, x = memorypar2), 

     position = position_jitter(width = .05), alpha = 0.5) +

   geom_boxplot(aes(colour = memorypar), outlier.colour = NA, position = dodge) +

   facet_wrap(~ process, nrow = 2)

p


查看完整回答
反對 回復 2019-12-27
?
HUH函數

TA貢獻1836條經驗 獲得超4個贊

在ggplot2版本中,1.0.0有一個新的位置被命名position_jitterdodge()為這種情況。此位置應在的內部使用,geom_point()并且應在的fill=內部使用,aes()以顯示要閃避數據的變量。要控制閃避的寬度,dodge.width=應使用參數。


ggplot(ex5,aes(x=tailindex ,y=hillest,color=memorypar,fill=memorypar))  + 

      facet_wrap(~process,nrow=2) + 

      geom_point(position=position_jitterdodge(dodge.width=0.9)) +

      geom_boxplot(fill="white",outlier.colour = NA, 

                        position = position_dodge(width=0.9))


查看完整回答
反對 回復 2019-12-27
  • 2 回答
  • 0 關注
  • 975 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號