R语言使用plot函数可视化数据、使用type参数自定义设置可视化的类型(数据点和线关系的类型)、设置type参数为p只有数据点没有线条

R语言使用plot函数可视化数据、使用type参数自定义设置可视化的类型(数据点和线关系的类型)、设置type参数为p只有数据点没有线条


R 是一个有着统计分析功能及强大作图功能的软件系统,是由奥克兰大学统计学系的Ross Ihaka 和 Robert Gentleman 共同创立。由于R 受Becker, Chambers & Wilks 创立的S 和Sussman 的Scheme 两种语言的影响,所以R 看起来和S 语言非常相似。

R语言被称作R的部分是因为两位R 的作者(Robert Gentleman 和Ross Ihaka) 的姓名,部分是受到了贝尔实验室S 语言的影响(称其为S 语言的方言)。

R 语言是为数学研究工作者设计的一种数学编程语言,主要用于统计分析、绘图、数据挖掘。

R语言原生plot函数能够满足基础可视化的绝大部分功能;

Function and argumentsOutput plot

plot(x, y)数值向量的散点图、Scatterplot of x and y numeric vectors

plot(factor)因子变量的柱状图、Barplot of the factor

plot(factor, y)数据变量的箱图;Boxplot of the numeric vector

and the levels of the factor

plot(time_series)时间序列图、Time series plot

plot(data_frame)dataframe中数据的相关性图;Correlation plot of all

dataframe columns

(more than two columns)

plot(date, y)可视化日期向量;Plots a date-based vector

plot(function, lower, upper)可视化函数的曲线;Plot of the function between the lower

and maximum value specified

plot函数中type参数的常用值;

Plot typeDescription

p数据点;Points plot (default)

l线图;Line plot

b点和线;Both (points and line)

o点和线、连接起来的;Both (overplotted)

s阶梯;Stairs plot

h类似直方图;Histogram-like plot

n不显示;No plotting

仿真数据

set.seed(123)

# Generate sample data

x <- rnorm(500)

y <- x + rnorm(500)

# Data

my_ts <- ts(matrix(rnorm(500), nrow = 500, ncol = 1),

              start = c(1950, 1), frequency = 12)

my_dates <- seq(as.Date("2005/1/1"), by = "month", length = 50)

my_factor <- factor(mtcars$cyl)

fun <- function(x) x^2

 R语言使用plot函数可视化数据、使用type参数自定义设置可视化的类型(数据点和线关系的类型)、设置type参数为p只有数据点没有线条

j <- 1:20

k <- j

par(mfrow = c(1, 3))

plot(j, k, type = "l", main = "type = 'l'")

plot(j, k, type = "s", main = "type = 's'")

plot(j, k, type = "p", main = "type = 'p'")

par(mfrow = c(1, 1))

par(mfrow = c(1, 3))

plot(j, k, type = "l", main = "type = 'o'")

plot(j, k, type = "s", main = "type = 'b'")

plot(j, k, type = "p", main = "type = 'h'")

par(mfrow = c(1, 1))

安利一个R语言的优秀博主及其CSDN专栏:

博主博客地址:

博主R语言专栏地址(R语言从入门到机器学习、持续输出已经超过1000篇文章)

参考:R

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容