Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 创建自定义轴时获取打印错误_R_Plot - Fatal编程技术网

R 创建自定义轴时获取打印错误

R 创建自定义轴时获取打印错误,r,plot,R,Plot,我在R的基本绘图系统中创建自定义轴时遇到问题,我有以下数据框,我想为其绘制趋势图,以显示每年的变化: year <- c(2000, 2002, 2005, 2009) values <- c(7332967, 5332780, 5135760, 3464206) x <- data.frame(year, values) ## year values ## 1 2000 733296 ## 2 2002 533278 ## 3

我在R的基本绘图系统中创建自定义轴时遇到问题,我有以下数据框,我想为其绘制趋势图,以显示每年的变化:

year  <- c(2000, 2002, 2005, 2009)
values  <- c(7332967, 5332780, 5135760, 3464206) 
x  <- data.frame(year, values)

##     year values
## 1    2000    733296
## 2    2002    533278
## 3    2005    513576
## 4    2009    346420
然而,对于数据帧中的四个值,这给了我一个倾斜的x轴和y轴。我希望x轴只包含年份列下的四个值,y轴只包含值列下的四个值

为此,我尝试创建自定义x轴和y轴,但这导致了错误:

plot(x$year, x$value,
     type = "b",
     xaxt = "n",
     yaxt = "n",
     xlab = "Year",
     ylab = "Values",
     axis(1, at = 1:nrow(x), labels = x$year),
     axis(2, at = 1:nrow(x), labels = x$value))

"Error in plot.window(...) : invalid 'xlim' value"
以及:

我对R很陌生,尝试在不同的网站上搜索解决方案,但是,似乎没有什么能解决问题,因此非常感谢提供的任何帮助。

轴是一个单独的函数,不是绘图参数,因此请尝试以下方法:

# First make some extra space on the left for the long numeric axis labels
par(mar=c(5, 6, 1, 1))
# Now plot the points, but suppress the axes
plot(x$year, x$values, xaxt='n', yaxt='n', xlab='Year', ylab='', type='b')
# Add the axes
axis(1, at=x$year, labels=x$year, cex.axis=0.8)
axis(2, at=x$values, labels=x$values, las=1, cex.axis=0.8)
# Add the y label a bit further away from the axis
title(ylab='Value', line=4)
plot(x$year, x$value,
     type = "b",
     xaxt = "n",
     yaxt = "n",
     xlab = "Year",
     ylab = "Values",
     axis(1, at = 1:nrow(x), labels = x$year),
     axis(2, at = 1:nrow(x), labels = x$value),
     xlim = c(min(data_plot$year), max(data_plot$year)),
     ylim = c(min(data_plot$Emissions), max(data_plot$Emissions)))

"Error in strsplit(log, NULL) : non-character argument"
# First make some extra space on the left for the long numeric axis labels
par(mar=c(5, 6, 1, 1))
# Now plot the points, but suppress the axes
plot(x$year, x$values, xaxt='n', yaxt='n', xlab='Year', ylab='', type='b')
# Add the axes
axis(1, at=x$year, labels=x$year, cex.axis=0.8)
axis(2, at=x$values, labels=x$values, las=1, cex.axis=0.8)
# Add the y label a bit further away from the axis
title(ylab='Value', line=4)