R语言 stars 位于 graphics 包(package)。
说明
绘制多元数据集的星形图或分段图。使用一个位置,还可以绘制‘spider’(或‘radar’)图。
用法
stars(x, full = TRUE, scale = TRUE, radius = TRUE, labels = dimnames(x)[[1]], locations = NULL, nrow = NULL, ncol = NULL, len = 1, key.loc = NULL, key.labels = dimnames(x)[[2]], key.xpd = TRUE, xlim = NULL, ylim = NULL, flip.labels = NULL, draw.segments = FALSE, col.segments = 1:n.seg, col.stars = NA, col.lines = NA, axes = FALSE, frame.plot = axes, main = NULL, sub = NULL, xlab = "", ylab = "", cex = 0.8, lwd = 0.25, lty = par("lty"), xpd = FALSE, mar = pmin(par("mar"), 1.1+ c(2*axes+ (xlab != ""), 2*axes+ (ylab != ""), 1, 0)), add = FALSE, plot = TRUE, ...)
参数
x数据的矩阵或 DataFrame 。将为 x 的每一行生成一个星形图或线段图。允许缺失值 ( NA ),但它们被视为 0(缩放后,如果相关的话)。
full逻辑标志:如果TRUE,线段图将占据一整圈。否则,它们仅占据(上)半圆。
scale逻辑标志:如果 TRUE ,则数据矩阵的列独立缩放,以便每列中的最大值为 1,最小值为 0。如果 FALSE ,则假设数据已被其他某个缩放算法范围
。
radius逻辑标志:在TRUE中,将绘制数据中每个变量对应的半径。
labels用于标记图的字符串向量。与 S 函数 stars 不同,如果 labels = NULL 则不会尝试构造标签。
locations具有用于放置每个线段图的 x 和 y 坐标的两列矩阵;或长度为 2 的数字,此时所有图都应叠加(对于“蜘蛛图”)。默认情况下, locations = NULL ,线段图将放置在矩形网格中。
nrow, ncol给出当 locations 为 NULL 时要使用的行数和列数的整数。默认情况下, nrow == ncol ,将使用方形布局。
len半径或线段长度的比例因子。
key.loc带有单位键的 x 和 y 坐标的向量。
key.labels用于标记单位键段的字符串向量。如果省略,则使用 dimnames(x) 的第二个组件(如果可用)。
key.xpd单位键的剪辑开关(绘图和标签),请参阅par("xpd")。
xlim具有要绘制的 x 坐标范围的向量。
ylim具有要绘制的 y 坐标范围的向量。
flip.labels逻辑指示标签位置是否应在图表之间上下翻转。默认为有点智能的启发式。
draw.segments合乎逻辑的。如TRUE画一个线段图。
col.segments颜色向量(整数或字符,请参阅 par ),每个向量指定其中一个段(变量)的颜色。如果 draw.segments = FALSE 则忽略。
col.stars颜色向量(整数或字符,请参阅 par ),每个向量指定其中一颗星星(案例)的颜色。如果 draw.segments = TRUE 则忽略。
col.lines颜色向量(整数或字符,请参阅 par ),每个向量指定其中一条线(案例)的颜色。如果 draw.segments = TRUE 则忽略。
axes逻辑标志:是否将 TRUE 轴添加到图中。
frame.plot逻辑标志:如果 TRUE ,则绘图区域被加框。
main情节的主要标题。
sub情节的副标题。
xlabx 轴的标签。
ylaby 轴的标签。
cex标签的字符扩展因子。
lwd用于绘图的线宽。
lty用于绘图的线型。
xpd逻辑或 NA 指示是否应进行裁剪,请参阅 par(xpd = .) 。
marpar(mar = *) 的参数,通常选择比默认情况更小的边距。
...更多参数,传递给 plot() 的第一次调用,请参见plot.default,如果 frame.plot 为 true,则传递给 box()。
add逻辑上,如果 TRUE 将星星添加到当前绘图中。
plot逻辑上,如果 FALSE ,则不会绘制任何内容。
细节
缺失值被视为 0。
每个星形图或线段图代表输入 x 的一行。变量(列)从右侧开始并逆时针绕圆圈旋转。 (缩放的)列的大小通过从中心到星形上的点的距离或代表变量的线段的半径来显示。
仅生成一页输出。
值
返回两列矩阵中绘图的位置,当 plot = TRUE 时不可见。
注意
该代码最初是由 David A. Andrews 绘制的空间星图。
之前R1.4.1,缩放仅将最大值移动到 1,尽管记录如下。
例子
require(grDevices) stars(mtcars[, 1:7], key.loc = c(14, 2), main = "Motor Trend Cars : stars(*, full = F)", full = FALSE) stars(mtcars[, 1:7], key.loc = c(14, 1.5), main = "Motor Trend Cars : full stars()", flip.labels = FALSE) ## 'Spider' or 'Radar' plot: stars(mtcars[, 1:7], locations = c(0, 0), radius = FALSE, key.loc = c(0, 0), main = "Motor Trend Cars", lty = 2) ## Segment Diagrams: palette(rainbow(12, s = 0.6, v = 0.75)) stars(mtcars[, 1:7], len = 0.8, key.loc = c(12, 1.5), main = "Motor Trend Cars", draw.segments = TRUE) stars(mtcars[, 1:7], len = 0.6, key.loc = c(1.5, 0), main = "Motor Trend Cars", draw.segments = TRUE, frame.plot = TRUE, nrow = 4, cex = .7) ## scale linearly (not affinely) to [0, 1] USJudge <- apply(USJudgeRatings, 2, function(x) x/max(x)) Jnam <- row.names(USJudgeRatings) Snam <- abbreviate(substring(Jnam, 1, regexpr("[,.]",Jnam) - 1), 7) stars(USJudge, labels = Jnam, scale = FALSE, key.loc = c(13, 1.5), main = "Judge not ...", len = 0.8) stars(USJudge, labels = Snam, scale = FALSE, key.loc = c(13, 1.5), radius = FALSE) loc <- stars(USJudge, labels = NULL, scale = FALSE, radius = FALSE, frame.plot = TRUE, key.loc = c(13, 1.5), main = "Judge not ...", len = 1.2) text(loc, Snam, col = "blue", cex = 0.8, xpd = TRUE) ## 'Segments': stars(USJudge, draw.segments = TRUE, scale = FALSE, key.loc = c(13,1.5)) ## 'Spider': stars(USJudgeRatings, locations = c(0, 0), scale = FALSE, radius = FALSE, col.stars = 1:10, key.loc = c(0, 0), main = "US Judges rated") ## Same as above, but with colored lines instead of filled polygons. stars(USJudgeRatings, locations = c(0, 0), scale = FALSE, radius = FALSE, col.lines = 1:10, key.loc = c(0, 0), main = "US Judges rated") ## 'Radar-Segments' stars(USJudgeRatings[1:10,], locations = 0:1, scale = FALSE, draw.segments = TRUE, col.segments = 0, col.stars = 1:10, key.loc = 0:1, main = "US Judges 1-10 ") palette("default") stars(cbind(1:16, 10*(16:1)), draw.segments = TRUE, main = "A Joke -- do *not* use symbols on 2D data!")
作者
Thomas S. Dye
参考
Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
也可以看看
symbols 另一种绘制星星和其他符号的方法。
相关用法
R stem 茎叶图 R stripchart 一维散点图 R strwidth 绘制字符串和数学表达式的维数 R smoothScatter 具有平滑密度颜色表示的散点图 R sunflowerplot 制作向日葵散点图 R spineplot 脊柱图和脊柱图 R symbols 绘制符号(圆形、正方形、星形、温度计、箱线图) R screen 在单个设备上创建和控制多个屏幕 R segments 将线段添加到绘图中 R legend 将图例添加到绘图中 R barplot 条形图 R plot.histogram 绘制直方图 R points 向绘图添加点 R mtext 将文本写入绘图的边距 R arrows 将箭头添加到绘图中 R contour 显示轮廓 R pairs 散点图矩阵 R box 在地块周围画一个方框 R coplot 调节图 R mosaicplot 马赛克图 R bxp 从摘要中绘制箱线图 R plot.raster 绘制光栅图像 R axTicks 计算轴刻度线位置 R curve 绘制函数图 R plot.factor 绘制因子变量注:本文由纯净天空筛选整理自R-devel大神的英文原创作品 Star (Spider/Radar) Plots and Segment Diagrams。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。