我正在尝试为一个情节生成一个图例,以在一个情节中显示颜色与聚类#的关系.我实际上并不需要它在图中我只想生成一个图例然后将其复制并粘贴到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)
Run Code Online (Sandbox Code Playgroud)
但我很难复制它.这是我的代码:
plot(seq(1,7), seq(1,7), col = c(1:7))
legend("topright", inset = .05, title = "Cluster Colors"
,fill = c(1:7), horiz=T)
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到此错误:
Error in as.graphicsAnnot(legend) :
argument "legend" is missing, with no default
Run Code Online (Sandbox Code Playgroud)
有什么建议?
原始情节有一个参数"传奇",它只是一个未命名的论点.在这里更新:
legend("topright", inset=.05, title="Number of Cylinders",
legend =c("4","6","8"), fill=terrain.colors(3), horiz=TRUE)
Run Code Online (Sandbox Code Playgroud)
所以,你需要的是这个.
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)
Run Code Online (Sandbox Code Playgroud)
该?命令?legend用于查找这些内容.