簡體   English   中英

使用DiagrammeR調整中介圖中的邊緣標簽位置?

[英]Adjust edge label position in mediation diagram with DiagrammeR?

我正在嘗試使用 R 中的DiagrammeR繪制標准的三角中介圖(它也可以解釋 graphviz 代碼)。 總的來說,它工作正常,但邊緣標簽文本的放置很奇怪。 底部邊緣標簽未居中,兩個傾斜的邊緣標簽位於不同的高度(參見下圖中的紅線)。 有沒有辦法手動為邊緣文本分配位置或獲得更一致的內容?`

library(DiagrammeR)

# Create a node data frame (ndf)
ndf <- create_node_df(
  n         = 3,
  label     = c("Experimental\nTreatment", "Some\nMediator", "Outcome\nof Interest"),
  shape     = rep("rectangle", 3),
  style     = "empty",
  fontsize  = 6,
  fixedsize = TRUE,
  height    = .5,
  width     = .75,
  color     = "gray40",
  x         = c(1, 2, 3),
  y         = c(1, 2, 1)
)

# Create an edge data frame (edf)
edf <- create_edge_df(
  from     = c(1, 1, 2),
  to       = c(2, 3, 3),
  label    = c("1.1*", "2.0*", "-0.33***"),
  fontsize = 6,
  minlen   = 1,
  color    = "gray40",
  )

# Create a graph with the ndf and edf
graph <- create_graph(
  nodes_df = ndf,
  edges_df = edf
  )

graph %>%
  render_graph()

顯示邊緣標簽文本未正確排列的示例中介圖

我也很想知道這個問題的答案。

我試圖通過以下方式刪除默認的“布局”圖形屬性並設置圖形布局的方向:

graphAttr <- DiagrammeR::get_global_graph_attrs(graph)

但是,我收到以下錯誤:錯誤:'get_global_graph_attrs' 不是來自 'namespace:DiagrammeR' 的導出對象

....因此,我被卡住了。

在使用DiagrammeR一段時間后,我最終切換到 LaTeX 圖表包TikZ 它允許對圖表的每個方面進行巨大的控制,但可能會讓人不知所措。 如果這很重要,TikZ 還需要進行一些調整才能將圖表轉換為 HTML 輸出。 對於使用 LaTeX 的 Beamer 類進行幻燈片的演示,使用 R 中的函數生成 TikZ 代碼效果很好。 然后將該 TikZ 代碼寫入一個文本文件,該文件可以通過 LaTeX 命令\\input{path/to/file.txt}自動導入,或者只是復制並粘貼到我的幻燈片中。

查看兩個 DiagrammeR 解決方案和 TikZ 解決方案的代碼,在這里: https ://stackoverflow.com/a/64886536/893399

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM