簡體   English   中英

Plotrix 標簽,調整大小/字體/位置?

[英]Plotrix labels, adjusting the size/font/position?

我一直在嘗試使用 plotly 和現在的 plotrix 創建風險雷達,但我遇到了兩者的限制(基於我的需要以及我的 R 技能)。

除了交易破壞者無法標記徑向軸(團隊 A、團隊 B 等)之外,我幾乎擁有我想要的大部分東西

我使用 plotrix 的這個版本幾乎是我需要的地方,只需要一些指導來讓我越過界限?

我有4個問題:

  1. 標題可以左右移動嗎?

  2. 徑向? 標簽滲入圖表圓圈使其難以閱讀,它們可以以某種方式進行調整嗎?

  3. 是否可以更改標簽 0/30/60/90/180 的字體(大小和/或顏色)?

  4. 無論如何要向繪制點添加文本,在我的情況下,我想將 RiskID 作為標簽

我的圖表如下所示: 在此處輸入圖片說明

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 或其他圖表包來實現最終結果的任何提示都會很棒。

你應該看看radial.plot.labelsradial.grid函數

# 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矢量化真是太遺憾了,這會讓這更容易

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

在此處輸入圖片說明

我不小心做了這個可愛的雪花@accidental__aRt

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

在此處輸入圖片說明

暫無
暫無

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

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