2015-09-06 34 views
0

我有下面這些代碼進出口試圖使成圓形圖使用R:在circlize圖調整標籤

我已閱讀vigenette,承認它的一些已經在我頭上有點驚人的包circlize ,

我想知道是否有一個快速的方法來刪除我的圖表上的所有標籤,包括刻度標記,並且只需按照與這個扇區相同的角度在淺灰色中添加回奧迪,沃爾沃和寶馬example

library (dplyr) 
library(circlize) 

df = read.table(textConnection(" 
Brand_from model_from Brand_to Model_to 
          VOLVO  s80  BMW 5series 
          BMW 3series  BMW 3series 
          VOLVO  s60 VOLVO  s60 
          VOLVO  s60 VOLVO  s80 
          BMW 3series  AUDI  s4 
          AUDI   a4  BMW 3series 
          AUDI   a5  AUDI  a5 
          "), header = TRUE, stringsAsFactors = FALSE) 


# Add customer satisfaction (1 being positive, 0 being negative) 
df <- df %>% 
    mutate(Customer.Sat = c("POS","NEG","NEG","POS","POS","NEG","NEG")) %>% 
    select(Brand_from,Brand_to,Customer.Sat) 

# Set the colour Scheme for the association 
col = c("NEG" = "red", 
    "POS" = "green") 

diffHeight = c("POS" = -0.02, 
      "NEG" = 0.04) 

# Build the Chord Diagram 
chordDiagram(df[1:2], 
     col = col[df$Customer.Sat], 
     diffHeight = diffHeight[df$Customer.Sat]) 

circos.clear() 

我看到有可能使用我所見過的答案Rotate labels in a chordDiagram (R circlize)這是非常相似

然而,這並不刪除現有的標籤,如刻度線和部門的名稱代碼

# Rotates the Labels so they are 90 Degrees to the chord diagram 
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) { 
xlim = get.cell.meta.data("xlim") 
ylim = get.cell.meta.data("ylim") 
sector.name = get.cell.meta.data("sector.index") 
circos.text(mean(xlim), ylim[1] + .1, sector.name, facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5)) 
circos.axis(h = "top", labels.cex = 0.5, major.tick.percentage = 0.2,  sector.index = sector.name, track.index = 2) 
}, bg.border = NA) 

基於page 17 of the vignette

回答

2

我在想,如果有一個快速的方法,以消除我的 圖,包括刻度標記,只是淺灰色以相同的角度加回奧迪,沃爾沃和寶馬 該部門的所有標籤爲每this example

你可以嘗試

chordDiagram(df[1:2], col = col[df$Customer.Sat], diffHeight = diffHeight[df$Customer.Sat], annotationTrack = "grid", preAllocateTracks = 1) 
circos.trackPlotRegion(track.index = 1, panel.fun = function(x, y) { 
    xlim = get.cell.meta.data("xlim") 
    ylim = get.cell.meta.data("ylim") 
    sector.name = get.cell.meta.data("sector.index") 
    circos.text(mean(xlim), ylim[1] + .1, sector.name, facing = "clockwise", niceFacing = TRUE, adj = c(0, 0.5), col = "lightgray") 
}, bg.border = NA) 

,讓你

enter image description here

+0

嗨lukeA謝謝你,你能解釋一下代碼嗎,這樣我就可以在將來更容易地拍出更復雜的例子.....感謝你的時間 –

+0

你會在小插曲中找到一個解釋:https: //cran.r-project.org/web/packages/circlize/vignettes/visualize_relations_by_chord_diagram.pdf#page=16 – lukeA