首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Plotrix标签,调整大小/字体/位置?

Plotrix标签,调整大小/字体/位置?
EN

Stack Overflow用户
提问于 2020-03-25 00:58:40
回答 1查看 512关注 0票数 0

我一直试图创建一个风险雷达使用巧妙的和现在的plotrix,我已经遇到了两种情况下(基于我的需要和我的技能与R)。

巧妙地说,我拥有了我想要的大部分东西,除了不能标记径向轴( A队、B队等)之外。

我的版本使用plotrix几乎是我需要的地方,只是需要一些指导才能让我越界?

我有四个问题:

  1. 标题可以移到左边还是右边?
  2. 桡骨?标签流进了图表圈,很难读懂,它们能被某种方式调整吗?
  3. 是否可以更改标签0/30/60/90/180的字体(大小和/或颜色)?
  4. 在我的例子中,我想用RiskID作为标签。

我的图表是这样的:

代码语言:javascript
复制
library(plotrix)

# Build sample dataset
aRiskID      <- c(1, 15, 23, 28, 35)
bRiskDays    <- as.numeric(c(28, 15, 85, 153, 100))
cTheta       <- as.integer(c(20, 80, 130, 240, 320))
dConsequence <- c("Major", "Major", "Minor", "Moderate", "Minor")

myRisks <- data.frame(RiskID = aRiskID, RiskDays = bRiskDays, Theta = cTheta, CurrentConsequence = dConsequence)

myLabels <- c("Team A", "Team B", "Team C", "Team D", "Team E", "Team F", "Team G", "Team H")

# Test different point colours
# initializing vector of colors as NA
colors_plot <- rep(NA,length(myRisks))

# set of conditions listed in the plot
colors_plot[myRisks$CurrentConsequence == "Major"]    <- "black"
colors_plot[myRisks$CurrentConsequence == "Moderate"] <- "red"
colors_plot[myRisks$CurrentConsequence == "Minor"]    <- "green"
# add more conditions as needed

# par(mar=c(2,5,5,5))

# plot the chart
radial.plot(myRisks$RiskDays,
            myRisks$Theta,
            start = pi/2,
            clockwise = FALSE,
           # start=pi/2,clockwise=TRUE,
            show.grid.labels=1,
            rp.type="s",
            main="Risk Radar",
            radial.lim=c(0,30,60,90,180),
            radlab = TRUE,
            point.symbols=17,
            point.col=colors_plot,
            cex = 2,
            cex.axis = 0.25,
            cex.lab = 0.25,
            lwd=par("lwd"),mar=c(2,2,3,2),
           # show.centroid=TRUE,
            labels=myLabels)

我不知道还有什么地方可以使用这个,所以任何使用plotrix或其他图表包来实现最终结果的提示都是很棒的。

EN

回答 1

Stack Overflow用户

发布于 2020-03-25 02:35:10

您应该看看函数radial.plot.labelsradial.grid

代码语言:javascript
复制
# plot the chart
radial.plot(myRisks$RiskDays,
            myRisks$Theta,
            start = pi/2,
            clockwise = FALSE,
            # start=pi/2,clockwise=TRUE,
            show.grid.labels=1,
            rp.type="s",
            # main="Risk Radar",
            radial.lim=c(0,30,60,90,180),
            radial.labels = '',
            radlab = TRUE,
            point.symbols=17,
            point.col=colors_plot,
            cex = 2,
            cex.axis = 0.25,
            cex.lab = 0.25,
            lwd=par("lwd"),mar=c(2,2,3,2),
            # show.centroid=TRUE,
            labels=NULL, label.pos = pi / 4 * 2:9)
# 1
mtext("Risk Radar", at = par('usr')[1], font = 2)
# 2
at <- c(0,30,60,90,180)
radial.plot.labels(max(at) + 35, pi / 4 * 2:9, labels = myLabels, radial.lim = at)
# 3
radial.plot.labels(at, pi / 2 * 3, labels = at, col = 1:5, cex = 1.5)
# 4
radial.plot.labels(myRisks$RiskDays, myRisks$Theta, start = pi/2,
                   clockwise = FALSE, labels = myRisks$RiskID)

如果您确实需要垂直的标签,您可以使用radial.grid函数或在标签上使用单独的旋转(srt)循环。很遗憾,srt没有在text中被矢量化,这会使这件事变得更容易

代码语言:javascript
复制
th <- pi / 4 * 2:9
sapply(seq_along(th), function(ii) {
  i <- ifelse((th[ii] > pi / 2) & (th[ii] < pi / 2 * 3), pi, 0)
  radial.plot.labels(max(at) + 35, th[ii], labels = myLabels[ii],
                     radial.lim = at, srt = (th[ii] - i) * 180 / pi)
})

我不小心把这个可爱的雪花做成了aRt

代码语言:javascript
复制
th <- pi / 4 * 2:9
sapply(th, function(x)
  radial.plot.labels(max(at) + 35, pi / 4 * 2:9, labels = myLabels,
                     radial.lim = at, srt = x * 180 / pi))

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60841576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档