gpt4 book ai didi

r - 如何定义(基础 R)散点图的固定纵横比

转载 作者:行者123 更新时间:2023-12-03 07:15:47 26 4
gpt4 key购买 nike

我正在绘制在两个群体的每个个体中测量的两种同位素的相关系数(值 = 0.0:1.0)。我希望散点图具有固定的纵横比,以便无论图形设备如何,x 轴和 y 轴的大小都完全相同。有建议吗?

这是我在 R 中的第一个图,任何有关我的代码改进的评论都值得赞赏吗?最后,是否值得投资学习基本绘图技术,还是应该直接跳到 ggplot2 或lattice?

我的情节脚本:

## Create dataset
WW_corr <-
structure(list(South_N15 = c(0.7976495, 0.1796725, 0.5338347,
0.4103769, 0.7447027, 0.5080296, 0.7566544, 0.7432026, 0.8927161
), South_C13 = c(0.76706752, 0.02320767, 0.88429902, 0.36648357,
0.73840937, 0.0523504, 0.52145159, 0.50707858, 0.51874445), North_N15 = c(0.7483608,
0.4294148, 0.9283554, 0.8831571, 0.5056481, 0.1945943, 0.8492716,
0.5759033, 0.7483608), North_C13 = c(0.08114805, 0.47268136,
0.94975596, 0.06023815, 0.33652839, 0.53055943, 0.30228833, 0.8864435,
0.08114805)), .Names = c("South_N15", "South_C13", "North_N15",
"North_C13"), row.names = c(NA, -9L), class = "data.frame")

opar <- par()

## Plot results
par(oma = c(1, 0, 0, 0), mar = c(4, 5, 2, 2))
plot(1,1,xlim=c(0:1.0), ylim=c(0:1.0), type="n", las=1, bty="n", main = NULL,
ylab=expression(paste("Correlation Coefficient (r) for ", delta ^{15},"N ",
"\u0028","\u2030","\u0029")),
xlab=expression(paste("Correlation Coefficient (r) for ", delta ^{13},"C ",
"\u0028","\u2030","\u0029")))

points(WW_corr$South_N15, WW_corr$South_C13, pch = 23, cex = 1.25,
bg ="antiquewhite4", col = "antiquewhite4")
points(WW_corr$North_N15, WW_corr$North_C13, pch = 15, cex = 1.25,
bg ="black")
axis(1, at = seq(0, 1.0, by = 0.1), labels = F, tick = TRUE, tck = -0.01)
axis(2, at = seq(0, 1.0, by = 0.1), labels = F, tick = TRUE, tck = -0.01)
abline(h=.86, v=.86, col = "gray60", lty = 2)
legend("topleft", c("North", "South"), pch = c(15, 23),
col = c("black", "antiquewhite4"), pt.bg = c("black", "antiquewhite4"),
horiz=TRUE, bty = "n")

par(opar)

最佳答案

par(pty="s")
plot(...)

将绘图类型设置为方形,这将在您的情况下完成工作(我认为),因为您的 x 和 y 范围是相同的。相当好的隐藏选项记录在 ?par 中。

关于r - 如何定义(基础 R)散点图的固定纵横比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8693558/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com