赞
踩
1.区间随机生成坐标刻度间距,坐标轴的间距刻度是自动随机设置:xlim和ylim的区间进行设置在[-20.20]
plot(1:30,xlim=c(-20,20),ylim=c(-20,20))
2.自定义设置坐标刻度间距
自己设置刻度步骤:
1.首先把plot里面默认的坐标轴关掉,参数是xaxt=‘n’;
2.其次,做完plot以后通过axis函数手动添加坐标轴;
例举原图像绘制效果如下:
a<-16:25
b<-c(57,81,86,89,91,126,139,155,200,211)
plot(a,b,type="b",xlab="网络节点数目 x1000",ylab="算法时间消耗",col="blue",xlim=c(16,25),ylim=c(57,211),pch=15)
用xaxt=“n”,yaxt="n"关掉之前存在的坐标轴的刻度
plot(a,b,type="b",xlab="网络节点数目 x1000",ylab="算法时间消耗",col="blue",xlim=c(16,25),ylim=c(57,211),pch=15,xaxt="n",yaxt="n")
然后,自己设置X轴,Y轴坐标刻度
axis(1,a) #设置X轴坐标刻度
axis(2,b) #设置Y轴坐标刻度
等间距的设置坐标轴的长度:如果想要将16到25,用10个数字刻度描述,每个刻度间的间隔是2.5一个单位长度,方法如下所示:
m=seq(from = 16, to = 25, by=2.5) ## 先生成等差数列的刻度,间距为2.5
plot(a,b,type="b",xlab="网络节点数目 x1000",ylab="算法时间消耗",col="blue",xlim=c(16,25),ylim=c(57,211),pch=15)
plot(a,b,type="b",xlab="网络节点数目 x1000",ylab="算法时间消耗",col="blue",xlim=c(16,25),ylim=c(57,211),pch=15,xaxt="n",yaxt="n")
axis(1,m) #设置X轴坐标刻度
axis(2,b) #设置Y轴坐标刻度
par(mfrow = c(1, 2))
plot(1:30,xlim=c(-20,20),ylim=c(-20,20),xlab="X轴",ylab="Y轴")
plot(1:30,xlim=c(-20,20),ylim=c(-20,20),cex.lab=1.8,xlab="X轴",ylab="Y轴")
par(mfrow = c(1, 2))
plot(1:30,xlim=c(-20,20),ylim=c(-20,20))
plot(1:30,xlim=c(-20,20),ylim=c(-20,20),cex.axis=2)
par(mfrow = c(1, 2))
plot(1:30,xlim=c(-20,20),ylim=c(-20,20),xlab="X轴",ylab="Y轴",main="测试")
plot(1:30,xlim=c(-20,20),ylim=c(-20,20),cex.main=4,xlab="X轴",ylab="Y轴",main="测试")
x <- seq(-4, 4, 0.01)
y <- x^2
par(mfrow = c(2, 2), mar = c(4, 4, 1, 1))
plot(x, y) # 未作处理
plot(x, y, xaxs = "i", yaxs ="i") # 绘图边框未留白
plot(x, y, bty = 'l') # 只保留左和下两条边框
plot(x, y, ann = F, bty = "n", xaxt = "n", yaxt ="n") # 边框、坐标轴都去掉
x <- c(1:10)
y <- x
z <- 10/x
z
opar <- par(no.readonly=TRUE)
par(mar = c(5,4,4,8)+0.1)
plot(x, y, type="b",
pch = 21, col = "red",
yaxt = "n", lty = 3, ann = FALSE)
lines(x, z, type = "b", pch = 22, col = "blue", lty = 2)
x <- c(1:10)
y <- x
z <- 10/x
z
opar <- par(no.readonly=TRUE)
par(mar = c(5,4,4,8)+0.1)
plot(x, y, type="b",
pch = 21, col = "red",
yaxt = "n", lty = 3, ann = FALSE)
lines(x, z, type = "b", pch = 22, col = "blue", lty = 2)
axis(2, at = x, labels = x, col.axis = "red", las = 2)
axis(4, at = x, labels = round(z, digits = 2),
col.axis = "blue", las = 2, cex.axis = 0.7, tck = -0.03)
x=c(1:10)
y=c(1:10)
plot(x,y,type="b",frame=FALSE,mgp=c(3,2,1))
a<-16:25
b<-c(57,81,86,89,91,126,139,155,200,211)
opar <- par(no.readonly=TRUE)
par(mar = c(5,4,4,8)+0.1)
plot(a,b,type="b",xlab="网络节点数目 x1000",ylab="算法时间消耗",col="blue",xlim=c(16,25),ylim=c(57,211),pch=15,ann = FALSE)
mtext("y = 1/x", side = 4, line = 3, cex.lab = 2, las = 2, col = "blue")
par(oma=c(3,3,3,3),mar=c(5,10,5,5),mgp=c(3,2,1),bty="o",xaxt='n')
plot(1:10,1:10,xlab="x",ylab="y",main="ILoveLittree",cex.axis=0.8,cex.lab=2)
box("inner", lty="dotted", col="red")
box("outer", lty="solid", col="blue")
mtext("注解:I am happy", side=1, cex.lab=1.3, line=1, cex=1.2,font.axis=2,outer=TRUE,adj=0)
x=seq(from=-5,to=5,by=0.01)
h=function(b){
w=(1+b^2)/(1+(b-1)^2)
2*log(w)
}
y=h(x)
plot(x,y,type='l', axes = FALSE)
h=function(b){
w=(1+b^2)/(1+(b-1)^2)
2*log(w)
}
x=seq(from=-5,to=5,by=0.01)
y=h(x)
plot(x,y,type='l', axes = FALSE)
arrows(-0.25,-1.76, -5, -1.76, length = 0,lty = 2)
arrows(1.25,1.76, 5, 1.76, length = 0,lty = 2)
arrows(-0.25,-2.1, -0.25, 2, length = 0,lty = 3)
arrows(1.25, -2.1, 1.25, 2, length = 0,lty = 3)
axis(2)
axis(1, at = c(-5, -0.25, 1.25, 5),
labels = c("Y1", "Xo", "X1", "Y2"))
plot(1:5, 1:5, type = "n", xlab = "X", ylab = "Y")
abline(h=c(3,4),v=c(3,4),lty=3,col="lightgray")
text(c(3,4),c(3,4),c("焦点中心1","焦点中心2"))
给图形中的点加上文本标签。
par(mfrow = c(1, 2))
attach(mtcars)
plot(wt,mpg,main = 'Mileage vs. Car Weight',xlab = 'Weight',ylab = 'Mileage',pch=18,col='blue')
plot(wt,mpg,main = 'Mileage vs. Car Weight',xlab = 'Weight',ylab = 'Mileage',pch=18,col='blue')
text(wt,mpg,row.names(mtcars),cex = 0.6,pos=4,col='red')
detach(mtcars)
data1 <- data.frame(A = 1:2, B = 1:2, C = 1:2)
data <- data.matrix(data1)
par(font = 2, lwd = 2)
bar=barplot(data, col = c("black", "pink"), beside = T, ylim = c(0, 2.5), font = 2)
text( bar, y = 0.05 + data[,1], adj = c(0.5, 0))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。