How can I plot a stars in color?
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)
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.
- Get the function source of
stars
, and make a copy: let's call itstars2
- Add an extra argument in the
stars2
argument list:col.lines = NULL
- Change the following of code from:
polygon(s.x[i, ], s.y[i, ], lwd = lwd, lty = lty, col = col.stars[i])
topolygon(s.x[i, ], s.y[i, ], lwd = lwd, lty = lty, border = col.lines[i], col = col.stars[i])
- 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))
精彩评论