开发者

How can I plot a stars in color?

开发者 https://www.devze.com 2023-03-27 09:18 出处:网络
I have开发者_运维百科 a 5x7 matrix I want to plot as a radar or spider chart?For example: stars(mtcars[, 1:7], locations = c(0,0), radius = FALSE,

I have开发者_运维百科 a 5x7 matrix I want to plot as a radar or spider chart? For example:

stars(mtcars[, 1:7], locations = c(0,0), radius = FALSE,
      key.loc=c(0,0), main="Motor Trend Cars", lty = 2)

How can I plot a stars in color?

I'd like each of these lines to be a different color (and/or different style) so I can make out what I'm looking at.


The following suggestion is a bit of a hack. I'm sure a more elegant solution is possible.

  1. Get the function source of stars, and make a copy: let's call it stars2
  2. Add an extra argument in the stars2 argument list: col.lines = NULL
  3. Change the following of code from: polygon(s.x[i, ], s.y[i, ], lwd = lwd, lty = lty, col = col.stars[i]) to polygon(s.x[i, ], s.y[i, ], lwd = lwd, lty = lty, border = col.lines[i], col = col.stars[i])
  4. Call stars2 providing a color for each of your stars.

The sample call and output (left = before, right = after) are below.

stars2(mtcars[, 1:7], locations = c(0,0), radius = FALSE,key.loc=c(0,0), 
       main="Motor Trend Cars", lty = 2,col.lines = 1:nrow(mtcars))

How can I plot a stars in color?

0

精彩评论

暂无评论...
验证码 换一张
取 消