[英]Plotrix labels, adjusting the size/font/position?
我一直在嘗試使用 plotly 和現在的 plotrix 創建風險雷達,但我遇到了兩者的限制(基於我的需要以及我的 R 技能)。
除了交易破壞者無法標記徑向軸(團隊 A、團隊 B 等)之外,我幾乎擁有我想要的大部分東西
我使用 plotrix 的這個版本幾乎是我需要的地方,只需要一些指導來讓我越過界限?
我有4個問題:
標題可以左右移動嗎?
徑向? 標簽滲入圖表圓圈使其難以閱讀,它們可以以某種方式進行調整嗎?
是否可以更改標簽 0/30/60/90/180 的字體(大小和/或顏色)?
無論如何要向繪制點添加文本,在我的情況下,我想將 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.labels
和radial.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.