我正在尝试为图生成图例,以显示颜色与图中群集#的关系。我实际上只需要生成图例,然后将其复制并粘贴到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
有什么建议?
最佳答案
原始图有一个参数“传奇”,它只是未命名的参数。如此处更新:
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
命令对于了解这些情况很有用。
关于r - R:图例()错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28997011/