R語言使用plot函數(shù)可視化數(shù)據(jù)诉瓦、使用type參數(shù)自定義設(shè)置可視化的類型(數(shù)據(jù)點和線關(guān)系的類型)川队、設(shè)置type參數(shù)為p只有數(shù)據(jù)點沒有線條
R 是一個有著統(tǒng)計分析功能及強大作圖功能的軟件系統(tǒng)力细,是由奧克蘭大學統(tǒng)計學系的Ross Ihaka 和 Robert Gentleman 共同創(chuàng)立睬澡。由于R 受Becker, Chambers & Wilks 創(chuàng)立的S 和Sussman 的Scheme 兩種語言的影響,所以R 看起來和S 語言非常相似眠蚂。
R語言被稱作R的部分是因為兩位R 的作者(Robert Gentleman 和Ross Ihaka) 的姓名煞聪,部分是受到了貝爾實驗室S 語言的影響(稱其為S 語言的方言)。
R 語言是為數(shù)學研究工作者設(shè)計的一種數(shù)學編程語言逝慧,主要用于統(tǒng)計分析昔脯、繪圖、數(shù)據(jù)挖掘笛臣。
R語言原生plot函數(shù)能夠滿足基礎(chǔ)可視化的絕大部分功能云稚;
Function and argumentsOutput plot
plot(x, y)數(shù)值向量的散點圖、Scatterplot of x and y numeric vectors
plot(factor)因子變量的柱狀圖沈堡、Barplot of the factor
plot(factor, y)數(shù)據(jù)變量的箱圖静陈;Boxplot of the numeric vector
and the levels of the factor
plot(time_series)時間序列圖、Time series plot
plot(data_frame)dataframe中數(shù)據(jù)的相關(guān)性圖;Correlation plot of all
dataframe columns
(more than two columns)
plot(date, y)可視化日期向量鲸拥;Plots a date-based vector
plot(function, lower, upper)可視化函數(shù)的曲線拐格;Plot of the function between the lower
and maximum value specified
plot函數(shù)中type參數(shù)的常用值;
Plot typeDescription
p數(shù)據(jù)點刑赶;Points plot (default)
l線圖捏浊;Line plot
b點和線;Both (points and line)
o點和線撞叨、連接起來的金踪;Both (overplotted)
s階梯;Stairs plot
h類似直方圖牵敷;Histogram-like plot
n不顯示热康;No plotting
仿真數(shù)據(jù)
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函數(shù)可視化數(shù)據(jù)、使用type參數(shù)自定義設(shè)置可視化的類型(數(shù)據(jù)點和線關(guān)系的類型)劣领、設(shè)置type參數(shù)為p只有數(shù)據(jù)點沒有線條
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語言的優(yōu)秀博主及其CSDN專欄:
博主R語言專欄地址(R語言從入門到機器學習姐军、持續(xù)輸出已經(jīng)超過1000篇文章)
參考:R