当前位置:网站首页>R language mapping: coordinate axis setting
R language mapping: coordinate axis setting
2022-07-23 19:36:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
To draw a pleasing statistical chart , The setting of coordinate axis is very important . stay R In the bottom drawing of language , The adjustment of coordinate axis is mainly through adjustment plot function 、axis Functions and title A series of parameters of the function complete .
plot(x,y, …)
axis(side,at = NULL, labels = TRUE, tick = TRUE, line = NA,
pos= NA, outer = FALSE, font = NA, lty = “solid”,
lwd = 1, lwd.ticks = lwd, col = NULL,col.ticks = NULL,
hadj = NA, padj = NA, …)
title(main= NULL, sub = NULL, xlab = NULL, ylab = NULL,
line = NA, outer = FALSE, …)
One 、plot Function preparation
Before personalization axis , It usually needs to be adjusted plot Function ann、bty、xaxt、yaxt、xaxs and yaxs Parameters :
ann take FALSE The title will not be drawn ( Including the main 、 Subtitle and axis title );
bty Used to set the border form , The default value is ”o”, It means that all four borders are drawn , Other optional values include ”l”( The lower left )、”7″( Up right )、”c”( Up, down, left )、”u”( Left down right )、”]” ( Up, down, right ) and ”n”( nothing , That is, no border ), In many personalized drawings ,bty Set to ”n”, Later border lines use other functions ( Such as axis) Add by yourself ;
xaxs and yaxs Used to set x Axis and y The scope of the shaft , Default value “r”, Indicates that the coordinate axis is smaller than the given drawing range ( Parameters xlim and ylim The scope given ) A little bigger , take ”i” Time indicates that the coordinate axis range is exactly the same as the given drawing range , It is also desirable ”s”、”e”、”d”;
xaxt and yaxt take ”n” when , Axis 、 The scale line and scale value will not be drawn .
x <- seq(-4, 4, 0.01)
y <- x^2
par(mfrow = c(2, 2), mar = c(4, 4, 1, 1))
plot(x, y) # Not processed
plot(x, y, xaxs = "i", yaxs ="i") # The drawing border is not left blank
plot(x, y, bty = 'l') # Keep only the left and bottom borders
plot(x, y, ann = F, bty = "n", xaxt = "n", yaxt ="n") # Frame 、 The axes are removed Two 、axis Function usage
1、 Basic operation
side Represents the coordinate axis to be operated , Value 1、2、3、4 On behalf of 、 Left 、 On 、 Right ;
at Indicates the position of the scale line and the scale value ;
labels Indicates the scale value ;
las Indicates the text direction of coordinate scale value ,las=0 Indicates that the text direction is parallel to the coordinate axis ,1 Indicates that it is always horizontal ,2 Indicates that it is perpendicular to the coordinate axis ,3 It means the end is vertical .
x<- seq(-4, 4, 0.01)
y<- x^2
par(mfrow=c(1, 2), mar = c(4, 4, 1, 1))
# Text direction is not set
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4)
axis(2,seq(0, 16, 4), seq(0, 16, 4))
# The text direction is horizontal
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, las = 1)
axis(2,seq(0, 16, 4), seq(0, 16, 4), las = 1)2、 Font size
cex.axis Indicates the font size of the scale value of the coordinate axis ,
font.axis Font representing the scale value of the coordinate axis ,font=1 Indicates orthography ,2 Indicates bold ,3 In italics ,4 Indicates Black Italic .
x<- seq(-4, 4, 0.01)
y<- x^2
par(mfrow=c(2, 2), mar = c(4, 4, 1, 1))
# Font size is not set
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4)
#cex.axis = 2
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, cex.axis = 2)
#font.axis = 2
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, font.axis = 2)
#font.axis = 3
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, font.axis = 3)3、 Color
col The color of the diagram , Use in axis The color of the coordinate axis and coordinate scale line in the function ;
col.axis Represents the color of the scale value of the coordinate axis ;
col.ticks Indicates the color of the scale line of the coordinate axis .
x<- seq(-4, 4, 0.01)
y<- x^2
par(mfrow=c(2, 2), mar = c(4, 4, 1, 1))
# No color set
plot(x,y, ann = F, bty = "n", xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4)
#col = 2
plot(x,y, ann = F, bty = "n", xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, col = 2)
#col.axis = 2
plot(x,y, ann = F, bty = "n", xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, col.axis = 2)
#col.ticks = 2
plot(x,y, ann = F, bty = "n", xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, col.ticks = 2)4、 Location
line Indicates the distance between the coordinate axis position and the image frame , Negative numbers will be drawn within the image border ;
mgp The default value is c(3, 1, 0), The three numbers represent the axis title 、 The scale value and the distance between the axis and the drawing border ;
tcl The default value is -0.5, The number indicates the length of the tick mark , A negative value means that the scale line is facing outward , It's positive and facing inward ;
pos Indicates the position of the axis ;
line.outer take TRUE when , The coordinate axis will be drawn at the edge of the canvas ;
hadj It refers to the distance that the scale value is adjusted along the parallel coordinate axis ;
padj It refers to the distance that the scale value is adjusted along the vertical coordinate axis .
x <- seq(-4, 4, 0.01)
y <- x^2
par(mfrow= c(2, 2), mar = c(4, 4, 1, 1))
# The scale value position is not set
plot(x, y, ann = F, xaxt = "n", yaxt ="n")
axis(1, -4:4, -4:4)
# Use line Adjust the position of the scale value
plot(x, y, ann = F, xaxt = "n", yaxt ="n")
axis(1, -4:4, -4:4, line = 2)
# Use mgp Adjust the position of the scale value
plot(x, y, ann = F, xaxt = "n", yaxt ="n")
axis(1, -4:4, -4:4, mgp = c(3, 2, 0))
# Use padj Adjust the position of the scale value
plot(x, y, ann = F, xaxt = "n", yaxt ="n")
axis(1, -4:4, -4:4, padj = 1)5、 other
tick take FALSE when , The coordinate axis and scale line are not drawn ;
lty Said linear , Use in axis The function represents the coordinate axis type ;
lwd Indicates the thickness of the line , Use in axis The thickness of the coordinate axis in the function ;
lwd.ticks Indicates the thickness of the scale line .
3、 ... and 、title Function usage
main、sub、xlab and ylab Respectively represent the main title 、 Subtitle 、x Axis title and y Axis title ;
cex.lab Indicates the font size of the axis title ;
font.lab The font that represents the axis title ;
col.lab Represents the color of the axis title ;
The rest of the parameters and axis The usage is the same in .
x<- seq(-4, 4, 0.01)
y<- x^2
par(mfrow=c(2, 2), mar = c(4, 4, 1, 1))
# No title
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4)
axis(2,seq(0, 16, 4), seq(0, 16, 4))
# Use title Set title
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, las = 1)
axis(2,seq(0, 16, 4), seq(0, 16, 4), las = 1)
title(xlab= 'x', ylab = 'y')
# Use line Adjusting position
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, las = 1)
axis(2,seq(0, 16, 4), seq(0, 16, 4), las = 1)
title(xlab= 'x', ylab = 'y', line = 2)
# Adjust the color font size
plot(x,y, ann = F, xaxt = "n", yaxt = "n")
axis(1,-4:4, -4:4, las = 1)
axis(2,seq(0, 16, 4), seq(0, 16, 4), las = 1)
title(xlab= 'x', ylab = 'y', col.lab = 2, font.lab = 4, cex.lab = 2)Four 、 Scale interval
plot Function will automatically give a reasonable scale interval , It's essentially a call to pretty function .
pretty(x, n = 5, min.n = n %/% 3, shrink.sml = 0.75, high.u.bias = 1.5, u5.bias = .5 + 1.5*high.u.bias, eps.correct = 0, …)
x It's a sequence ,pretty The function will first correct x Take a range, Then divide it into approximately n+1 An interval . If you are not satisfied with the interval automatically given by the system when drawing , You can adjust n Value , use pretty Function to customize the appropriate interval .
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/126792.html Link to the original text :https://javaforall.cn
边栏推荐
- H7-TOOL的CANFD/CAN接口脱机烧写操作说明, 已经更新(2022-07-12)
- mBio | 海洋所孙超岷组在深海原位验证了微生物介导的单质硫形成新通路
- impala的详细写入流程
- Data link layer -------- Ethernet and ARP
- Terminal command (all)
- Type-C Bluetooth speaker single C-Port rechargeable OTG solution
- TCL scripting language foundation (2)
- 二叉树高度 [log2n]+1与log2(n+1)是否相等
- R语言data.table包进行数据分组聚合统计变换(Aggregating transforms)、计算dataframe数据的分组最小值(min)
- A preliminary study of the relationship between combinatorial mathematics and DP, and the derivation of resettable combinatorial formulas
猜你喜欢

时代潮头,华为将风帆对准数字金融的风与海

使用 frp 实现内网穿透

小鱼送激光雷达啦 | 恰饭即抽奖第一期

What content does the software test plan include and how to write it. Share test plan template

H7-TOOL的I2C接口方式脱机烧录操作方法,已经发布(2022-07-16)

作为一名后台开发人员,你必须知道的两种过滤器

小熊拍学习之LED灯的点亮

J9数字论:数字行业的FOMO现象我们应该怎么克服?

Codeforces Round #809 (Div. 2)【VP记录】

Tuple error caused by different regularization
随机推荐
虹科干货 | 教您如何解析MODBUS中的浮点型数据
【leetcode天梯】链表 · 206 反转链表
【C语言】程序环境和预处理
使用 frp 实现内网穿透
There is great competition pressure for software testing jobs, and the "migrant workers" who graduated from 985 also suffer
Understand chisel language. 21. Chisel sequential circuit (I) -- detailed explanation of chisel register
[C language] program environment and preprocessing
树学习总结
Publish the local image to Alibaba cloud warehouse
有向图之求两点之间所有路径
What are offline data and real-time data
MySQL 啥时候用表锁,啥时候用行锁?
一道题目初探组合数学与DP关系,可重集组合公式推导
吃透Chisel语言.21.Chisel时序电路(一)——Chisel寄存器(Register)详解
进程调度的基本过程
R语言检验样本是否符合正态性(检验样本是否来自一个正态分布总体):使用nortest包的sf.test函数检验样本是否符合正态分布(normality test)
结构体大小的计算(结构体内存对齐)
Ros2 self study notes: rviz visualization tool
R语言ggpubr包的ggarrange函数多幅图像组合起来、annotate_figure组合图像添加注释、注解、标注信息、使用top参数在可视化图像顶部添加注解信息(自定义字体颜色、大小、样式)
MySQL数据库【数据库基础--引入篇】