简体   繁体   English

R 星图较小的 unit.key

[英]R star plot smaller unit.key

The following command will generate a star plot,以下命令将生成一个星图,

stars(mtcars[, 1:7], key.loc = c(14, 1.5), main = "Motor Trend Cars : full stars()")

how to make the unit key(bottom right corner) smaller or bigger?如何使单位键(右下角)变小或变大? 在此处输入图片说明

If I understand properly, you want to increase the key polygon leaving the same size of the data polygons.如果我理解正确,您想增加关键多边形,留下与数据多边形相同的大小。 Unfortunatelly, it is not possible.不幸的是,这是不可能的。 If we look at the source code of the stars() function, we will establish that the size of the both data and key polygons is controlled by the same argument len .如果我们查看stars()函数的源代码,我们将确定数据和关键多边形的大小都由相同的参数len

However, you may write you own modified stars() function making that possible.但是,您可以编写自己的修改过的stars()函数,使之成为可能。 One way is to add an additional argument for the the key expansion, and define a separate length argument for the legend一种方法是为键扩展添加一个额外的参数,并为图例定义一个单独的长度参数

stars2 <- function (x, key.exp = 1, .....)
{
    key_expansion <- key.exp
    len_legend <- key_expansion * len
    ...
}

Then the new length argument len_legend should be applied to draw the key instead of the old len argument.然后应该应用新的长度参数len_legend来绘制键而不是旧的len参数。 Thaht is, len should be replaced by len_legend inside the code which draws the key unit (the whole code chunk inside the if (!is.null(key.loc)) { .... } statement), like this:也就是说, len应该在绘制关键单元的代码中替换为len_legendif (!is.null(key.loc)) { .... }语句中的整个代码块),如下所示:

   if (!is.null(key.loc)) {
        par(xpd = key.xpd)
        key.x <- len_legend * cos(angles) + key.loc[1L]
        key.y <- len_legend * sin(angles) + key.loc[2L]
       ...
   }

Let's check the results:让我们检查一下结果:

pdf("res_stars.pdf")
par(mfrow = c(1, 2))
    stars(mtcars[, 1:7], 
        key.loc = c(14, 1.5), 
        main = "Motor Trend Cars : full stars()",
        cex = 0.3)
    stars2(mtcars[, 1:7], 
        key_expansion = 1.3,
        key.loc = c(14, 1.5), 
        main = "Motor Trend Cars : full stars()",
        cex = 0.3)
dev.off()

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM