阅读权限 255 威望 0 级论坛币 2444 个 通用积分 60.5031 学术水平 69 点 热心指数 78 点 信用等级 44 点 经验 4348 点 帖子 160 精华 0 在线时间 399 小时 注册时间 2008-4-14 最后登录 2025-7-29
A piece-by-piece solution using {graphics} only:
# Data for plotting
head(dfPlt)
# mnt hrl prv
# 北京 1650 16.9 <U+5317><U+4EAC>
# 上海 1620 14.0 <U+4E0A><U+6D77>
# 广东 1550 15.0 <U+5E7F><U+4E1C>
# 新疆 1520 15.2 <U+65B0><U+7586>
# 天津 1500 15.0 <U+5929><U+6D25>
# 江苏 1480 13.0 <U+6C5F><U+82CF>
# Function to add a fan-shape with text inside and outside in the plot
pltFan <-
function(cnt.arc, arc, r.in, r.out, text.in = character(0), text.out = character(0), text.in.cex = 0.5, text.out.cex = text.in.cex, ...)
{
# Fan-shape
polygon(c(r.in*cos(cnt.arc - arc/2), r.in*cos(cnt.arc + arc/2), r.out*cos(cnt.arc + arc/2), r.out*cos(cnt.arc - arc/2)), c(r.in*sin(cnt.arc - arc/2), r.in*sin(cnt.arc + arc/2), r.out*sin(cnt.arc + arc/2), r.out*sin(cnt.arc - arc/2)), ...)
# Text inside
text((r.in - par()$cxy[2]*text.in.cex)*cos(cnt.arc), (r.in - par()$cxy[2]*text.in.cex)*sin(cnt.arc), text.in, adj = c(0.5, 0.5), srt = cnt.arc/2/pi*360 - 90, cex = text.in.cex)
# Text outside
text((r.out + par()$cxy[2]*text.out.cex)*cos(cnt.arc), (r.out + par()$cxy[2]*text.out.cex)*sin(cnt.arc), text.out, adj = c(0.5, 0.5), srt = cnt.arc/2/pi*360 - 90, cex = text.out.cex)
}
# Number of records to plot
iNbar <- nrow(dfPlt)
# Optionally, map additional font - Windows only
windowsFonts(KT = windowsFont("KaiTi"))
# Plot in .png format
png("salary.png", width = 960, height = 960)
# Maximizing the plot area
par(mar = c(0, 0, 0, 0))
# Call plot.new with a few settings
plot(c(-2, 2), c(-2, 2), type = "n", axes = F, xlab = "", ylab = "", asp = 1, xlim = c(-2, 2), ylim = c(-2, 2))
# Do the plot
sapply( 0:(iNbar - 1), function(i)
{
# Text inside
pltFan(cnt.arc = pi/2 - (i*2*pi/(iNbar + 1) + 2*pi/(iNbar + 1)*(1/4 + 1/8 + 1/4)/2), arc = 2*pi/(iNbar + 1)*(1/4 + 1/8 + 1/4), r.in = 1, r.out = 2, text.in = dfPlt[i + 1, "prv"], text.out = NULL, col = NULL, border = NA, text.in.cex = 1)
# Monthly data
pltFan(cnt.arc = pi/2 - (i*2*pi/(iNbar + 1) + 2*pi/(iNbar + 1)/8), arc = 2*pi/(iNbar + 1)/4, r.in = 1, r.out = dfPlt[i + 1, "mnt"]/1000, text.in = NULL, text.out = as.character(dfPlt[i + 1, "mnt"]), text.out.cex = 1, col = "orange", border = NA)
# Hourly data
pltFan(cnt.arc = pi/2 - (i*2*pi/(iNbar + 1) + 2*pi/(iNbar + 1)*(2 + 1 + 1)/8), arc = 2*pi/(iNbar + 1)/4, r.in = 1, r.out = dfPlt[i + 1, "hrl"]/20 + 1, text.out.cex = 1, text.in = NULL, text.out = as.character(dfPlt[i + 1, "hrl"]), col = "yellow", border = NA)
} )
# Legend and other texts in the plot
legend(2, -1.5, c("月最低工资标准", "小时最低工资标准"), col = c("orange", "yellow"), bty = "n", cex = 1.25, pt.cex = 1.2, pch = c(15, 15), xjust = 1, yjust = 1) -> lgnd
# If no font mapping is done, remove the family option
text(lgnd$rect$left, lgnd$rect$top - lgnd$rect$h, "注:数字为截至2014年\n5月1日的执行标准", adj = c(0, 1), cex = 1.25, family = "KT")
text(-2.1, 1.75, "全国各省(区、直辖市)\n2014年最低工资标准", cex = 1.75, adj = c(0, 1))
text(-2.1, 1.75 - par()$cxy[2]*4, "(单位:元)", cex = 1.25, adj = c(0, 1))
dev.off() 复制代码 Result:
总评分: 经验 + 100
论坛币 + 110
学术水平 + 6
热心指数 + 2
查看全部评分