当前位置:网站首页>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
边栏推荐
- What content does the software test plan include and how to write it. Share test plan template
- 使用 frp 实现内网穿透
- R语言作图:坐标轴设置
- Leetcode daily question (1514. path with maximum probability)
- not all arguments converted during string formatting
- Gvim/vim tips
- Tree learning summary
- R语言data.table包进行数据分组聚合统计变换(Aggregating transforms)、计算dataframe数据的分组最小值(min)
- 关于:在企业局域网中启用 Delivery Optimization
- Little fish sends lidar | just dinner is the first lottery
猜你喜欢
随机推荐
MySQL 啥时候用表锁,啥时候用行锁?
H7-TOOL的CANFD/CAN接口脱机烧写操作说明, 已经更新(2022-07-12)
Detailed explanation of TCL scripting language (1)
界面设计四大原则
Type-C Bluetooth speaker single C-Port rechargeable OTG solution
《自适应机器人交互白皮书》
socat 使用「建议收藏」
有向图之求两点之间所有路径
R语言使用ggpubr包的ggarrange函数将多幅图像组合起来、使用ggexport函数将可视化图像保存为bmp格式(width参数指定宽度、height参数指定高度、res参数指定分辨率)
Alibaba's latest masterpiece! It took 187 days for the liver to come out. 1015 pages of distributed full stack manuals are so delicious
为啥一问 JVM 就 懵B ?
Publish the local image to Alibaba cloud warehouse
R语言作图:坐标轴设置
LeetCode刷题:回文数
【luogu P6656】【LOJ 173】【模板】Runs(字符串)(Lyndon 串)
【开发经验】开发项目踩坑集合【持续更新】
【leetcode天梯】链表 · 022 链表中倒数第k个节点
解密:智能化变电站中PTP时钟同步(北斗时钟服务器)
.Net CLR R2R编译的原理简析
What content does the software test plan include and how to write it. Share test plan template









