[英]R plot, x-axis and y-axis touching
我的問題涉及為R中的出版物制作圖表。我使用了如下的繪圖函數:
plot(x=data$SL, y=data$BD, xlab = "SL (mm)", ylab = "BD (mm)", pch=data$pch)
SL范圍從51.7到73.7,BD從13.5到20.4。 不幸的是我還不允許發布圖片。
但是,想要擺脫我用“軸= F”的盒子。 現在的問題是缺乏對軸功能的控制。 我用了:
axis(side=1, lwd=3, xpd=TRUE, at=c(min(data$SL):max(data$SL)))
axis(side=2, lwd=3, xpd=TRUE, at=c(min(data$BD):max(data$BD)))
問題是我無法設法讓y軸和x軸在與框圖中的相同點上聚集在一起。 如何讓x軸和y軸相互接觸?
最有可能設置xaxs =“i”和yaxs =“i”將幫助您獲得所需的行為。
plot(c(1,2,3),c(2,4,6),axes=F,xaxs = "i",yaxs="i",xlim=c(0,3),ylim=c(0,6))
axis(side=1, lwd=3, xpd=TRUE, at=0:3)
axis(side=2, lwd=3, xpd=TRUE, at=seq(0,6,2))
嘗試box(bty='L')
僅繪制框的左下部分。 您也可以使用lines
, segments
或abline
自己繪制lines
,並使用grconvertX
和grconvertY
函數來查找繪制線條的位置。
我建議您按照您概述的程序進行操作,然后使用:
box(which = "plot", bty = "l")
例如:
plot.new()
plot.window(xlim = c(1, 18), ylim = c(2, 20))
points(1:18, 2:19, pch = 1, col = "#FF7F24", cex = 1.2)
lines(1:18, 2:19, col = "#FF7F24", lwd = 2)
axis(side = 1,
lwd = 0,
lwd.ticks = 1,
at = 1:18,
cex.axis = 0.9)
title(main = "Plot",
ylab = "Y-Axis")
legend("top",
legend = c("Legend"),
col = c("#FF7F24"),
text.col = c("#FF7F24"),
pch = 1,
bty = "n",
cex = 1.2)
axis(side = 2,
lwd = 0,
lwd.ticks = 1)
box(which = "plot", bty = "l")
您應該將選項lwd = 0
和lwd.ticks = 1
傳遞給您的單獨axis()
調用,以防止軸的某些部分比軸的其他部分顯得更胖,因為有些部分會被您對box()
調用覆蓋有些人沒有。
我認為最后使用box()
的解決方案更為通用,因為你可以使用它,例如你不能或不想在plot.default
或plot.window
調用中傳遞bty = "l"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.