我正在尝试为图生成一个图例,以在图中显示颜色与cluster #的关系。我实际上并不需要在绘图中使用它,我只是想生成一个图例,然后将其复制并粘贴到powerpoint幻灯片中。
我在这里找到了这段代码,它实现了我想要的功能:
http://www.statmethods.net/advgraphs/axes.html
# Legend Example
attach(mtcars)
boxplot(mpg~cyl, main="Milage by Car Weight",
yaxt="n", xlab="Milage", horizontal=TRUE,
col=terrain.colors(3))
legend("topright", inset=.05, title="Number of Cylinders",
c("4","6","8"), fill=terrain.colors(3), horiz=TRUE)
但我很难复制它。下面是我的代码:
plot(seq(1,7), seq(1,7), col = c(1:7))
legend("topright", inset = .05, title = "Cluster Colors"
,fill = c(1:7), horiz=T)
当我运行它时,我得到这个错误:
Error in as.graphicsAnnot(legend) :
argument "legend" is missing, with no default
有什么建议吗?
发布于 2015-03-12 05:07:23
原来的图有一个参数"legend",它只是一个未命名的参数。更新如下:
legend("topright", inset=.05, title="Number of Cylinders",
legend =c("4","6","8"), fill=terrain.colors(3), horiz=TRUE)
所以,你需要的是这个。
plot(seq(1,7), seq(1,7), col = c(1:7))
legend("topright", inset = .05, title = "Cluster Colors",legend= c(1:7)
,fill = c(1:7), horiz=TRUE)
与?legend
中的命令一样,?
命令对于了解这些内容很有用。
https://stackoverflow.com/questions/28997011
复制相似问题