R:在圆图中调整标签 [英] R: Adjusting Labels in circlize diagram

查看:260
本文介绍了R:在圆图中调整标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码,我试图使用令人惊叹的软件包circlize将其制作成圆形图

I have the code below which im trying to make into a circular diagram using the amazing package circlize

我已经阅读过小插页,并承认其中有些已经超出我的头顶了,

I have read the vigenette and admit some of it has gone over my head a bit,

我想知道是否有一种快速的方法来删除图表上的所有标签,包括刻度线,并按照此示例

I was wondering if there is a quick way to remove all the labels on my diagram including tick marks and just add back in AUDI, VOLVO and BMW in light grey at the same angle to the sector as per this 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()

我看到有可能基于第17页,小插曲使用代码

I see that it is possible based on page 17 of the vignette using the code

# 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)

我已经看到在chordDiagram中旋转标签的答案(R循环) 非常相似

但是,这不会删除现有的标签,例如刻度线和扇区名称.

However this does not remove the existing labels such as tick marks and names of the sectors.

推荐答案

我想知道是否有一种快速的方法来删除我所有的标签 包括刻度线的图表,只需添加回奥迪,沃尔沃和宝马 与此示例

I was wondering if there is a quick way to remove all the labels on my diagram including tick marks and just add back in AUDI, VOLVO and BMW in light grey at the same angle to the sector as per 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)

这给你

这篇关于R:在圆图中调整标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆