r - 围绕绘图中的圆圈环绕/弯曲文本 (R)

标签 r text graphics

有没有机会写出“包裹”在圆圈周围的文字?我的意思是这样的:enter image description here

最佳答案

您也可以试试 arctextplotrix包:

library(plotrix)

# set up a plot with a circle
plot(x = 0, y = 0, xlim = c(-2, 2), ylim = c(-2, 2))
draw.circle(x = 0, y = 0, radius = 1)

# add text
arctext(x = "wrap some text", center = c(0, 0), radius = 1.1, middle = pi/2)
arctext(x = "counterclockwise", center = c(0, 0), radius = 1.1, middle = 5*pi/4,
        clockwise = FALSE, cex = 1.5)
arctext(x = "smaller & stretched", center = c(0, 0), radius = 1.1, middle = 2*pi ,
        cex = 0.8, stretch = 1.2)

enter image description here

要获得更多的定制机会(轻描淡写;请参阅漂亮的小插图),您可以查看 circlize包。通过设置 facing = "bending"circos.text ,文本环绕一个圆圈。
library(circlize)

# create some angles, labels and their corresponding factors
# which determine the sectors 
deg <- seq(from = 0, to = 300, by = 60)
lab <- paste("some text", deg, "-", deg + 60)   
factors <- factor(lab, levels = lab)

# initialize plot
circos.par(gap.degree = 10)
circos.initialize(factors = factors, xlim = c(0, 1))
circos.trackPlotRegion(ylim = c(0, 1))

# add text to each sector  
lapply(factors, function(deg){
  circos.updatePlotRegion(sector.index = deg, bg.col = "red")
circos.text(x = 0.5, y = 0.5, labels = as.character(deg), facing = "bending")
})
circos.clear()

enter image description here

更新 :
circlize version 0.2.1 , circos.text有两个新选项:bending.inside与原始 bending 相同和 bending.outside (参见 the vignette 中的图 11)。因此,使用 bending.outside 可以很容易地转动绘图下半部分的文本。 :
circos.par(gap.degree = 10)
circos.initialize(factors = factors, xlim = c(0, 1))
circos.trackPlotRegion(ylim = c(0, 1))

lapply(factors[1:3], function(deg){
  circos.updatePlotRegion(sector.index = deg, bg.col = "red")
  circos.text(x = 0.5, y = 0.5, labels = as.character(deg), facing = "bending.outside")
})

lapply(factors[4:6], function(deg){
  circos.updatePlotRegion(sector.index = deg, bg.col = "red")
  circos.text(x = 0.5, y = 0.5, labels = as.character(deg), facing = "bending.inside")
})
circos.clear()

enter image description here

关于r - 围绕绘图中的圆圈环绕/弯曲文本 (R),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27638826/

相关文章:

c++ - 从 WIC 图像 C++ 获取 RGB

c# - 如何画一条可选择的线?

r - 是否有任何服务、扩展可以缩小 R 代码?

c#如何使用图形路径制作平滑的圆弧区域

r - R 中带有字符串的 geom_smooth

java - 面板中的居中字符串

c# - 使用带分隔符的文本文件

javascript - 新的 div 不接受文本值

在 R 中舍入选定的 data.table 列

r - 如何在R中给定阈值和缓冲时间来过滤时间序列?