文章目录

  • 利用par()函数设置公共绘图参数(重点)
  • 在已有的plot图像中如何添加线条
  • 做出三维表面图
  • 控制坐标轴显示的区域
  • 在指定坐标中做注释
  • 标题和xy的标签
  • 标题中的字体
  • 通过title()对图形的坐标轴名称和图形标题进行编辑(重点)
  • 是否显示坐标轴
  • 是否显示坐标刻度
  • 通过axis()函数对坐标轴进行编辑(重点)
    • 参数
    • 例子
  • plot中的缩放
  • 图例
  • 颜色代码大全
    • R语言中的调色板

利用par()函数设置公共绘图参数(重点)

par()的功能有点想ggplot中的theme()可以对图形的很多参数进行设置,例如:
par(mfrow=c(2,2))#设置2*2的图形排列
par(family=‘XXX’)#设置作图区域的字体
par(font=1或2或3或4)#设置字型,正常体,font=1, 粗体,font=2,斜体,font=3, 粗斜体,font=4
par(las={0,1,2,3})#设置坐标轴字体的显示格式1-3分别对应正常,水平,与坐标轴正交,一直垂直

在已有的plot图像中如何添加线条

abline(v =1)#添加垂直的辅助线
abline(h=1)#添加水平的辅助线
lines(x,y)#添加由向量x,y组成的线条

做出三维表面图

persp(x,y,z,phi=-45,theta=45,col="yellow",shade=.65 ,ticktype="detailed")

控制坐标轴显示的区域

plot(xlim=c(a,b),ylim=c(c,d))

在指定坐标中做注释

text(x,y,"text")

标题和xy的标签

plot(x,y,main="dfdf",xlab="fdsf",ylab="sdafgsdafg",xlim=c(1,2),ylim=c(1,2))

或者

labs(title="dfdf",x="fdsf",y="sdafgsdafg")

标题中的字体

text(x,y,label="font=1 正常体",font=1)

正常体,font=1
粗体,font=2
斜体,font=3
粗斜体,font=4

通过title()对图形的坐标轴名称和图形标题进行编辑(重点)

title(xlab='XX',ylab='XXX', title='XXX',family=XX)

该函数也是在原有的基础上再进行操作,因为在plot阶段一般不显示这些名称

是否显示坐标轴

plot(x,y,axes=F)

是否显示坐标刻度

plot(x,y,xaxt="n")#不现实x轴的刻度
plot(x,y,yaxt="n")#不现实y轴的刻度

通过axis()函数对坐标轴进行编辑(重点)

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, gap.axis = NA, cex.axis = 1, ...)

通过at,labels组合可以指定坐标轴的刻度显示;
axis()是在原有的坐标轴的基础上再加一些参数,因此常和plot(…,xaxt=''n)配合使用, 以保证没有原始坐标轴刻度的干扰;
cex.axis=1.5,cex.lab=1.5,cex.main=1.5三个参数可以分别放大坐标刻度字体的大小,lab的字体大小,和标题的字体大小

参数

side
an integer specifying which side of the plot the axis is to be drawn on. The axis is placed as follows: 1=below, 2=left, 3=above and 4=right.

at
the points at which tick-marks are to be drawn. Non-finite (infinite, NaN or NA) values are omitted. By default (when NULL) tickmark locations are computed, see ‘Details’ below.

labels
this can either be a logical value specifying whether (numerical) annotations are to be made at the tickmarks, or a character or expression vector of labels to be placed at the tickpoints. (Other objects are coerced by as.graphicsAnnot.) If this is not logical, at should also be supplied and of the same length. If labels is of length zero after coercion, it has the same effect as supplying TRUE.

tick
a logical value specifying whether tickmarks and an axis line should be drawn.

line
the number of lines into the margin at which the axis line will be drawn, if not NA.

pos
the coordinate at which the axis line is to be drawn: if not NA this overrides the value of line.

outer
a logical value indicating whether the axis should be drawn in the outer plot margin, rather than the standard plot margin.

font
font for text. Defaults to par(“font”).

lty
line type for both the axis line and the tick marks.

lwd, lwd.ticks
line widths for the axis line and the tick marks. Zero or negative values will suppress the line or ticks.

col, col.ticks
colors for the axis line and the tick marks respectively. col = NULL means to use par(“fg”), possibly specified inline, and col.ticks = NULL means to use whatever color col resolved to.

hadj
adjustment (see par(“adj”)) for all labels parallel (‘horizontal’) to the reading direction. If this is not a finite value, the default is used (centring for strings parallel to the axis, justification of the end nearest the axis otherwise).

padj
adjustment for each tick label perpendicular to the reading direction. For labels parallel to the axes, padj = 0 means right or top alignment, and padj = 1 means left or bottom alignment. This can be a vector given a value for each string, and will be recycled as necessary.

If padj is not a finite value (the default), the value of par(“las”) determines the adjustment. For strings plotted perpendicular to the axis the default is to centre the string.

gap.axis
an optional (typically non-negative) numeric factor to be multiplied with the size of an ‘m’ to determine the minimal gap between labels that are drawn, see ‘Details’. The default, NA, corresponds to 1 for tick labels drawn parallel to the axis and 0.25 otherwise, i.e., the default is equivalent to

perpendicular <- function(side, las) {
is.x <- (side %% 2 == 1) # is horizontal x-axis
( is.x && (las %in% 2:3)) ||
(!is.x && (las %in% 1:2))
}
gap.axis <- if(perpendicular(side, las)) 0.25 else 1
gap.axis may typically be relevant when at = … tick-mark positions are specified explicitly.


other graphical parameters may also be passed as arguments to this function, particularly, cex.axis, col.axis and font.axis for axis annotation, i.e. tick labels, mgp and xaxp or yaxp for positioning, tck or tcl for tick mark length and direction, las for vertical/horizontal label orientation, or fg instead of col, and xpd for clipping. See par on these.

Parameters xaxt (sides 1 and 3) and yaxt (sides 2 and 4) control if the axis is plotted at all.

Note that lab will partial match to argument labels unless the latter is also supplied. (Since the default axes have already been set up by plot.window, lab will not be acted on by axis.)

例子

plot(x,y)
axis(side=1, at=1:4,labels=LETTERS[1:4])#改变刻度显示
#构造更加多样的坐标轴
axis(4, col = "violet", col.axis = "dark violet", lwd = 2)
axis(3, col = "gold", lty = 2, lwd = 0.5)

plot中的缩放

plot(x,y,xlab = 'x',main = 'title',ylab = 'y',cex.main = 1.5,cex.lab = 1.2)

图例

legend("topright",c("4k及以下","4k~6k","6k~8k","8k及以上"),lty=c(,,,),pch = c(, ,),col=c(,,,),lwd=c(,,,),fill=c("red","blue","black","green"),text.col = "green4",cex=0.6, merge = TRUE)

颜色代码大全

https://www.cnblogs.com/cnblogs-jcy/p/5689033.html

R语言中的调色板

 palette(value) # obtain the curren palette or set the palettepalette.pals() # give the names of predefined palettespalette.colors() # return a vector of R colors

R语言中作图的一些基本代码相关推荐

  1. R语言中作图字体的设置

    介绍 在R语言中设置字体时需要利用**windowsFonts()**加入到字体库中,例如: windowsFonts(myFont = windowsFont("微软雅黑")) ...

  2. R语言中的基础作图和ggplot2配色系统

    文章目录 颜色代码大全 R语言中的调色板 RColorBrewer提供的调色盘 R语言中配色介绍 R语言中自带的调色板 RColorBrewer包提供更多的调色板 ggplot2中配色系统的介绍 数值 ...

  3. tmap | R语言中专门绘制地图的工具包

    tmap工具包的名称是Thematic Maps的缩写,是R中专门绘制地图的工具包.该包语法与ggplot2包比较类似,都是通过符合+来进行图层叠加. 加载示例数据: library(tidyvers ...

  4. c语言调色板5个参数,R语言中的颜色以及色板

    可视化数据时,色彩往往是最欠考虑的因素.的确,在一个图中,数据的选择和图表类型的确定才是最重要,最需要确定的因素.但是,适当的选择颜色不仅仅能使数据图的阅读者赏心悦目,而且有助于图中数据关系的呈现,使 ...

  5. R语言中如何进行PCA分析?利用ggplot和prcomp绘制基因表达量分析图

    学习笔记的主要内容是在R语言中利用ggplot2进行PCA分析和绘图,包括简单分析与操作流程,对比不同方式得到的结果差异,提供脚本代码供练习. PCA分析的原理 在处理基因差异表达数据时,有时候需要分 ...

  6. R语言中主要的颜色对照图

    R语言作图,颜色的选择是比较头疼的事情,以下向大家分享R语言中主要的几百种颜色对照图.

  7. R语言中读取excel数据的常用方式有哪些?

    R语言中读取excel数据的常用方式有哪些? 目录 R语言中读取excel数据的常用方式有哪些? R语言是解决什么问题的? R语言中读取excel数据的常用方式有哪些? R语言是解决什么问题的? R ...

  8. R语言中可视化图像的标题太长如何进行换行?

    R语言中可视化图像的标题太长如何进行换行? 目录 R语言中可视化图像的标题太长如何进行换行? R语言是解决什么问题的? R语言中可视化图像的标题太长如何进行换行? R语言是解决什么问题的? R 是一个 ...

  9. R语言中使用pkgbuild::find_rtools查看是否有Rtools、使用Sys.which函数查看make是否存在、如果没有则安装、使用writeLines函数绑定R和Rtools

    R语言中使用pkgbuild::find_rtools(debug = TRUE)查看是否有Rtools.使用Sys.which函数查看make是否存在.如果没有则安装Rtools.使用writeLi ...

最新文章

  1. MySQL更新命令_UPDATE
  2. iOS下JS与OC互相调用(五)--UIWebView + WebViewJavascriptBridge
  3. MySQL中的视图操作
  4. Ubuntu-Python安装 scipy,numpy,matplotlib
  5. (一)Linux基础(1)
  6. Lambda表达式及应用
  7. LeetCode 535. Encode and Decode TinyURL
  8. 【网络安全工程师面试合集】—CSRF跨站请求伪造 攻击及防御
  9. Winform界面中实现通用工具栏按钮的事件处理
  10. 如何让vs2005的网站编译成一个DLL
  11. Ubuntu 16.04 源添加
  12. matlab报错随笔
  13. linux 文件读写 加速,MMAP文件加速读写小技俩
  14. 论文阅读 A SIMPLE BUT TOUGH-TO-BEAT BASELINE FOR SEN- TENCE EMBEDDINGS
  15. echarts中国地图,省市标注代码
  16. cad连筋字体怎么安装_你还在为CAD带“?”号头疼吗?丨CAD2500份字体大全及安装方法丨...
  17. 游戏中的心理学(四):让用户掏腰包的秘密
  18. Windows 10 21H2正式版镜像
  19. 视频字幕 硬字幕 软字幕 外挂字幕 简介
  20. 实现用户登录注册代码(高级代码)

热门文章

  1. 《宝贝三十六计》游戏策划方案
  2. vue设置路由登录权限
  3. mysql开启/关闭安全模式
  4. 多次异步请求,结果返回顺序的问题
  5. python中的大括号{}的用法
  6. 监控报警系统搭建及二次开发经验
  7. 堆球问题,开普勒猜想(格密码相关)
  8. Umount解挂不了的解决方法
  9. 【转】LINUX内核编译步骤详细介绍
  10. Fiddler 遇到 Certificate Error 解决方法