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

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

ggplot2兩行帶有表達式的標簽

ggplot2兩行帶有表達式的標簽

慕尼黑5688855 2019-10-18 09:49:47
我想用一條expression()語句在兩行上寫一個軸標簽。但是,plotmath并且expression也不允許這樣做(例如,在最右邊顯示帶下標的文本)。我在2005年左右發現了類似問題的討論,但是他們提供的解決方案并沒有轉化為ggplot2中的我的應用程序。最近的一個問題解決了多行表達式語句的其他排列問題,但是同樣,此處提供的解決方法也不適用。例:p <- ggplot(mtcars,aes(x=wt,y=mpg))+  geom_point()+  xlab(expression(paste("A long string of text goes here just for the purpose \n of illustrating my point Weight "[reported])))try(ggsave(plot=p,filename=<some file>,height=4,width=6))產生一個圖像,當我希望下標“ reported”位于前一個單詞的旁邊時,該圖像會被踢到右側。 
查看完整描述

3 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

你可以用這個把戲


library(gridExtra)

library(grid)


element_custom <- function() {

  structure(list(), class = c("element_custom", "element_text"))

}


element_grob.element_custom <- function(element, label="", ...)  {


  mytheme <- ttheme_minimal(core = list(fg_params = list(parse=TRUE, 

                                                         hjust=0, x=0.1)))

  disect <- strsplit(label, "\\n")[[1]]

  tableGrob(as.matrix(disect), theme=mytheme)

}


# default method is unreliable

heightDetails.gtable <- function(x) sum(x$heights)


ggplot(iris, aes(Sepal.Length, Sepal.Width)) +

  geom_line() + 

  labs(x= "First~line \n italic('and a second') \n integral(f(x)*dx, a, b)")+

  (theme_grey() %+replace% theme(axis.title.x = element_custom()))

http://img1.sycdn.imooc.com//5da91aaa00019aac04810446.jpg

查看完整回答
反對 回復 2019-10-18
  • 3 回答
  • 0 關注
  • 1649 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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