第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

gggplot 2-在圖外注釋

gggplot 2-在圖外注釋

尚方寶劍之說 2019-07-02 17:25:36
gggplot 2-在圖外注釋我想把樣本大小值和圖上的點(diǎn)聯(lián)系起來。我可以用geom_text將數(shù)字定位到接近點(diǎn)的位置,但這是混亂的。如果沿著地塊的外部邊緣把他們排成一排,那就更干凈了。例如,我有:df=data.frame(y=c("cat1","cat2","cat3"),x=c(12,10,14),n=c(5,15,20))ggplot(df,aes(x=x,y=y,label=n))+geom_point()+geom_text(size=8,hjust=-0.5)產(chǎn)生這個(gè)情節(jié):我更喜歡這樣的東西:我知道我可以創(chuàng)建第二個(gè)情節(jié)grid.arrange(A)a la這個(gè)職位)但是,確定textGrobs與y軸之間的間距是很繁瑣的。有更簡單的方法嗎?謝謝!
查看完整描述

3 回答

?
LEATH

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊

你不需要再畫一個(gè)情節(jié)。你可以用annotation_custom將Grobs定位在繪圖區(qū)域內(nèi)或之外的任何位置。Grobs的定位是根據(jù)數(shù)據(jù)坐標(biāo)進(jìn)行的。假設(shè)“5”、“10”、“15”與“cat 1”、“cat 2”、“cat 3”對齊,TextGrobs的垂直定位將由三個(gè)數(shù)據(jù)點(diǎn)的y坐標(biāo)給出。默認(rèn)情況下,ggplot2剪輯格羅布到繪圖區(qū)域,但裁剪可以被覆蓋。需要擴(kuò)大有關(guān)的差額,以便為格羅布會議騰出空間。下面(使用ggplot 2 0.9.2)給出了與第二幅圖類似的圖:

library (ggplot2)library(grid)df=data.frame(y=c("cat1","cat2","cat3"),x=c(12,10,14),n=c(5,15,20))p <- ggplot(df, aes(x,y)) + geom_point() +    
        # Base plot
     theme(plot.margin = unit(c(1,3,1,1), "lines"))   # Make room for the grobfor (i in 1:length(df$n))  {p <- p + annotation_custom(
      grob = textGrob(label = df$n[i], hjust = 0, gp = gpar(cex = 1.5)),
      ymin = df$y[i],      # Vertical position of the textGrob
      ymax = df$y[i],
      xmin = 14.3,         # Note: The grobs are positioned outside the plot area
      xmax = 14.3)
 }    # Code to override clippinggt <- ggplot_gtable(ggplot_build(p))gt$layout$clip[gt$layout$name == "panel"] <- "off"grid.draw(gt)


查看完整回答
反對 回復(fù) 2019-07-02
?
白豬掌柜的

TA貢獻(xiàn)1893條經(jīng)驗(yàn) 獲得超10個(gè)贊

基于grid


require(grid)


df = data.frame(y = c("cat1", "cat2", "cat3"), x = c(12, 10, 14), n = c(5, 15, 20))


p <- ggplot(df, aes(x, y)) + geom_point() + # Base plot

theme(plot.margin = unit(c(1, 3, 1, 1), "lines"))


p


grid.text("20", x = unit(0.91, "npc"), y = unit(0.80, "npc"))

grid.text("15", x = unit(0.91, "npc"), y = unit(0.56, "npc"))

grid.text("5", x = unit(0.91, "npc"), y = unit(0.31, "npc"))


查看完整回答
反對 回復(fù) 2019-07-02
  • 3 回答
  • 0 關(guān)注
  • 1635 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號