r - 在R中绘制图例之外的图例
问题描述
我正在尝试将图例放在情节之外,xpd=TRUE
但传说一直在情节中绘制。我怎样才能解决这个问题?
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))
解决方案
使用 inset 并使 xpd 为 true
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))
推荐阅读
- loops - 如何在循环中导航低谷范围和填充范围?
- python - Windows 上的 Python 64 位:OSError: [WinError 193] %1 is geen geldige Win32-toepassing
- processing - 处理中静止物体的自适应背景减法
- vue.js - Vue Axios - 使用 bootstrapVue 和 vuex,上传文件和文本仍有问题?
- javascript - 如何使用正则表达式对不同的字母(不一定是连续的)进行分组
- github - 如何取消 github/pypi 项目上的功能
- swiftui - 在 Swift UI 中垂直居中文本
- sql - 如何选择除原始行之外的所有重复行?
- sql - 需要帮助从光标中进行选择,就像它是工作台一样
- azure-devops - 用于 Azure 管道的类似 Go.CD 的界面