R 直线和对数x轴在绘图中给出水平回归线

R 直线和对数x轴在绘图中给出水平回归线,r,math,graphics,R,Math,Graphics,首先,请从下载我的数据集,然后执行以下脚本内容以获得一些散点图: # read data and attach it survey <- read.table("survey_oss.csv", header=TRUE) attach(survey) # plot for inhabitants png("scatterINHABT.png") plot(INHABT, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS", las=1)

首先,请从下载我的数据集,然后执行以下脚本内容以获得一些散点图:

# read data and attach it
survey <- read.table("survey_oss.csv", header=TRUE)
attach(survey)

# plot for inhabitants
png("scatterINHABT.png")
plot(INHABT, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS", las=1)
abline(lm(OSSADP~INHABT)) # regression line (y~x)
dev.off()

# plot for inhabitants divided by 1000
png("scatterINHABT_divided.png")
plot(INHABT/1000, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS", las=1)
abline(lm(OSSADP~INHABT)) # regression line (y~x)
dev.off()

# plot for inhabitants in logarithmic scale
png("scatterINHABT_log.png")
plot(INHABT, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS", las=1, log="x")
abline(lm(OSSADP~INHABT)) # regression line (y~x)
dev.off()

# plot for inhabitants in logarithmic scale and divided by 1000
png("scatterINHABT_log_divided.png")
plot(INHABT/1000, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS", las=1, log="x")
abline(lm(OSSADP~INHABT)) # regression line (y~x)
dev.off()
#读取数据并附加数据

调查科学记数法不久前已经介绍过,但是您可以使用
options()$scipen控制R选择何时进入科学记数法的方式

其次,除以1000的问题是,在
绘图
基线
中都没有除以1000。这将实现以下目的:

plot(INHABT/1000, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS")
abline(lm(OSSADP~I(INHABT/1000))) # Fixed regression line.
I
是必需的,因为
/
符号在
公式中具有不同的含义


另外,您的
las
参数是不必要的。

我在使用
log=“x”
时解决了水平线的问题,如下所示:

plot(INHABT, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS", log="x")
abline(lm(OSSADP~log10(INHABT)))

使用
log10
而不仅仅是
log

非常感谢您的回答。我决定使用千分法,简单地用
xlim=c(0215)
排除三个异常值,这样就不需要对数刻度了。但是,如果有人知道一个解决方案来协调此方法与对数x轴,请分享。哦,如果我不包括选项
las=1
R将垂直而不是水平显示y轴刻度的数字。
plot(INHABT, OSSADP, xlab="Inhabitants", ylab="Adoption of OSS", log="x")
abline(lm(OSSADP~log10(INHABT)))