且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

R 图形的次要刻度线、参考线、图例和文本标注 | 学习笔记

更新时间:2022-09-05 14:26:09

开发者学堂课程【大数据之 R 语言速成与实战R 图形的次要刻度线、参考线、图例和文本标注】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址https://developer.aliyun.com/learning/course/363/detail/4331


R 图形的次要刻度线、参考线、图例和文本标注

 

内容简介:

一、次要刻度线

二、参考线

三、图例

四、文本标注


一、次要刻度线

>install.packages("Hmisc")

warning in install. Packages

downloaded length 86016 !=reported lenqth 207547

Installing package into'C:/users/YH/Documents/R/win-1ibrary/3.2'

(as 'lib'is unspecified)

trying URL 'http://cran.rstudio.com/bin/windows/contrib/3.2/Hmisc_3.17-1.zip ' content type'application/zip'lenqth 1632748 bytes (1.6 MB)

downloaded 1.6 MB

package'Hmisc' successfully unpacked and MD5 sums checked  The downloaded binary packages are in

C:\Users\YH\AppData\Local\Temp\RtmpqgwOEd\ downloaded_packages

>libr ary(Hmisc)

Loading required package:lattice

Loading required package: survival

Loading requir ed package:Formula

Loading required package: ggplot2

 

Attaching package:'Hmisc'

The folowing objects are masked from'package:base': format.pva,round.POSIXt,trunc.POSIxt,units

>plot(1:4,1:4,type=“b”)

>minor.tick(nx=3,ny=2,tick,ratio=0.5)

 

二、参考线(对某个点进行标注)

abline(h=2,col"red",lty=2)

Error:unexpected string constant in"abline(h=2,col"red""

>abline(h=2,col="red",lty=2)

>abline(v=2,col="blue",lty=1)


三、图例

使用 legend(函数来添加图例,格式为∶legend(location,title,legend,….)

 

四、文本标注

●文本标注

●使用text()函数和mtext()将文本添加到图形上,text())可向绘图区域内部添加文本,而mtext()则向图形的四个边界之一添加文本.

●格式分别为∶

●text(location,"text to place", pos,...)

●Mtext('"text to place",side, line=n,…..)