首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在R中绘制绘图外部图例

在R中绘制绘图外部图例
EN

Stack Overflow用户
提问于 2018-06-07 17:06:58
回答 2查看 13.8K关注 0票数 3

我尝试使用xpd=TRUE将图例放在绘图之外,但图例一直在绘图内绘图。我该如何解决这个问题呢?

代码语言:javascript
复制
x = c(0,0,1,1,1)
y = c(0.4991,1.1423,1.2258,1.158,0.5148)
dat<-cbind(x,y)
point_shape = c(10,15,10,15,1)
dat<-data.frame(x,y,point_shape)

myTicks<-c(0,1)
plot(dat[,1],dat[,2], yaxt="n", xaxt="n", xlab="", ylab="",pch = dat$point_shape)
abline(0.4991,0.7267)
abline(1.1423,0.0157)
abline(0.4991,0.0157,lty=2)
axis(side = 1, at = myTicks)
axis(side = 2, at = myTicks)


legend("bottomleft", legend = c("apple", "orange", "tree"),
       bty = "n", xpd=FALSE, mar(c(7,7,7,7)), cex = 1, pch = c(10, 15, 1))
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-06-07 17:12:32

请参阅legend的帮助

也可以通过将x设置为列表中的单个关键字“bottom right”、"bottom“、”bottom left“、"left”、"topleft“、"top”、“top right”、"right“和”

“来指定位置。这会将图例放在绘图框架内的给定位置。

因此,您可以通过手动提供图例的坐标将图例放置在绘图区域之外:

代码语言:javascript
复制
legend(-0.2, 0.3, legend = c("apple", "orange", "tree"),
       bty = "n", xpd=TRUE, mar=c(7,7,7,7), cex = 1, pch = c(10, 15, 1))
票数 0
EN

Stack Overflow用户

发布于 2018-06-07 17:21:46

使用inset并将xpd设置为true

代码语言:javascript
复制
legend("bottomleft", legend = c("apple", "orange", "tree"), inset=c(-0.15,0),
   bty = "n", xpd=TRUE, mar(c(7,7,7,7)), cex = 1, pch = c(10, 15, 1))
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50737256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档