gpt4 book ai didi

r - 使用 R 的不同绘图系统在 0 处绘制垂直线和水平线

转载 作者:行者123 更新时间:2023-12-01 13:15:58 26 4
gpt4 key购买 nike

我已经检查了我的问题的答案,我能找到的最接近的答案在这里:Why does plot behave differently for same but scaled data? .我了解原子对象并已转换为数据框。

我加载了一些化学 react 数据:

   library(car)

theURL <- "http://lib.stat.cmu.edu/datasets/Andrews/T30.1"
theNames <- c("Table", "Number", "Row", "Experiment", "Temperature",
"Concentration", "Time", "Unchanged", "Converted", "Unwanted")
Reaction <- read.table(theURL, header = F , col.names = theNames)
Reaction <- Reaction[-c(1:4)]

然后我画了一个散点图;通过 X 的平均值和 Y 的平均值的实线;虚线表示± 2SDs。还有一段斜率 Sy/Sx 在 ± 5SDs 处绘制,因为我无法让 abline() 绘制它。

    scatterplot(Reaction$Temperature, Reaction$Converted, smooth = FALSE, 
regLine = FALSE, grid = FALSE, xlim = c(150, 185), xlab = "Temperature", ylab = "% Converted", main = "Reaction Results", ylim = c(45, 70))
TempMean = mean(Reaction$Temperature)
ConvMean = mean(Reaction$Converted)
TempSD = sd(Reaction$Temperature)
ConvSD = sd(Reaction$Converted)
abline(col = c("red", "green"), v = TempMean, h = ConvMean)
abline(col = "green", lty = "dotted", v = (c(TempMean - 2*TempSD, TempMean + 2*TempSD)))
abline(col = "red", lty = 3, h = (c(ConvMean - 2*ConvSD, ConvMean + 2*ConvSD)))
segments(TempMean - 5*TempSD, ConvMean - 5*ConvSD, TempMean + 5*TempSD, ConvMean + 5*ConvSD)

Bonferroni(?) Limits for bivariate data

...现在是大揭秘。如果我对所有内容进行缩放,散点图基本上会做同样的事情。

    # Scale Reaction Data
Reaction.scaled <- as.data.frame(scale(Reaction))
# Mean and sd Lines
scatterplot(Reaction.scaled$Temperature, Reaction.scaled$Converted, smooth = FALSE, regLine = FALSE, grid = FALSE, xlab = "Temperature", ylab = "% Converted", main = "Reaction Results")
TempMean = mean(Reaction.scaled$Temperature)
ConvMean = mean(Reaction.scaled$Converted)
TempSD = sd(Reaction.scaled$Temperature)
ConvSD = sd(Reaction.scaled$Converted)
abline(col = c("red", "green"), v = TempMean, h = ConvMean)
abline(col = "green", lty = "dotted", v = (c(TempMean - 2*TempSD, TempMean + 2*TempSD)))
abline(col = "red", lty = 3, h = (c(ConvMean - 2*ConvSD, ConvMean + 2*ConvSD)))
segments(TempMean - 5*TempSD, ConvMean - 5*ConvSD, TempMean + 5*TempSD, ConvMean + 5*ConvSD)

Scaled Plot

...但绘图未显示 (0,0) 处的缩放平均值。我怀疑这与高级和低级图形功能有关。

最佳答案

一如既往,这个问题是由于我自己对文档的误解造成的。

?scatterplot

reset.par
if TRUE (the default) then plotting parameters are reset to their previous values when scatterplot exits; if FALSE then the mar and mfcol parameters are altered for the current plotting device. Set to FALSE if you want to add graphical elements (such as lines) to the plot.

事实上,将 reset.par = FALSE 添加到上面基于汽车的散点图是可行的。自己在家试试吧!

引起问题的相关图形,更正: Scaled data with solid lines at means, dotted lines at means±2SDs

关于r - 使用 R 的不同绘图系统在 0 处绘制垂直线和水平线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55014941/

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