gpt4 book ai didi

Axis 在中心的 R 图

转载 作者:行者123 更新时间:2023-12-04 00:41:15 25 4
gpt4 key购买 nike

默认情况下,R 中的笛卡尔坐标 Axis 位于绘图的底部和左侧。
如何使坐标 Axis 居中,如下图所示?

enter image description here

例子

## using; data; generated; by; bgoldst;;
## estimate curve
x <- seq(-1,1.5,0.1);
y <- c(1.3,1.32,1.33,1.32,1.25,1.1,0.7,0.5,0.4,0.38,0.4,0.41,0.42,0.43,0.44,0.4,0.3,0.1,0,-0.05,-0.1,-0.15,-0.2,-0.24,-0.28,-0.3);
f <- splinefun(x,y);

## calculate precise points along estimated curve
x <- seq(-1,1.5,0.01);
y <- f(x);
plot(x, y, type = 'l')

enter image description here

最佳答案

@ForrestRStevens 对我来说太快了,我正忙着尝试使用样条曲线估计你的曲线 :)

## estimate curve
x <- seq(-1,1.5,0.1);
y <- c(1.3,1.32,1.33,1.32,1.25,1.1,0.7,0.5,0.4,0.38,0.4,0.41,0.42,0.43,0.44,0.4,0.3,0.1,0,-0.05,-0.1,-0.15,-0.2,-0.24,-0.28,-0.3);
f <- splinefun(x,y);

## calculate precise points along estimated curve
x <- seq(-1,1.5,0.01);
y <- f(x);

## precompute limits
xlim <- c(min(x),max(x));
ylim <- c(min(y)-0.4,max(y)+0.2);

## set global plot params
par(xaxs='i',yaxs='i',mar=c(1,1,3,3)+0.1); ## "internal" axis spacing, meaning no extended range, and slightly adjust margins

## draw plot
plot(NA,xlim=xlim,ylim=ylim,axes=F,ann=F); ## set plot bounds, no default ornaments
arrows(c(0,xlim[1]),c(ylim[1],0),c(0,xlim[2]),c(ylim[2],0),0.05); ## draw custom axes
mtext('y',3,1,at=0,las=1,cex=0.8,family='serif'); ## y label
mtext('x',4,1,at=0,las=1,cex=0.8,family='serif'); ## x label
lines(x,y,col='#aaaacc'); ## draw line on top

plot

一般来说,您几乎可以使用基础图形绘制任何东西,但与使用更复杂的包相比,它通常更加复杂,因为您必须手工绘制所有东西。

关于 Axis 在中心的 R 图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30658177/

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