日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

R手册(Visualise)--ggplot2

發布時間:2024/3/24 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 R手册(Visualise)--ggplot2 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

  • Overview
  • Geoms
    • 基本圖形
    • 單變量
    • 雙變量
    • 三變量
    • 文本
    • 誤差可視化
    • 地圖
  • Stats
  • Scales
    • 常用標尺格式
    • 坐標軸標尺
    • Color and fill scales
    • Shape and size scales
  • Coordinate Systems
  • Position Adjustments
  • Themes
  • Faceting
  • Annotations and Labels
  • Legends
  • Vector helpers
  • 混合圖
  • [ggplot2 extensions](https://blog.csdn.net/qq_41518277/article/details/80516938)

Overview

ggplot2 基于the grammar of graphics思想,通過數據集、幾何對象和坐標系統建立圖形。

所有的ggplot2繪圖都以ggplot()開始, 默認由aes()將數據集映射至幾何對象。在行尾+添加圖層:幾何,比例尺,坐標和面等。要將繪圖保存,請使用ggsave()

完整的ggplot2圖形包括:

  • ggplot(data,aes(...)): Create a new ggplot (required)
  • geom_<FUNC>(aes(...),data,stat,position): Geometric object (required)
    or stat_<FUNC>(aes(...),data,geom,position): Statistical transformation (required)
  • coord_<FUNC>(...): Coordinate systems
  • facet_<FUNC>(...): Facetting
  • scale_<FUNC>(...): Scales
  • theme_<FUNC>(...): Themes

data, aes參數可以在ggplot, geom_<FUNC>, stat_<FUNC>任一函數中加載

aes() 控制數據中的變量映射到幾何圖形。aes()映射可以在ggplot()和geom圖層中設置。常用參數:alpha, color, group, linetype, size

ggsave(filename, plot = last_plot(),path=NULL,width, height, units= c("in", "cm", "mm"))保存ggplot2圖形,默認保存最后一個圖

qplot(),quickplot(): Quick plot


Geoms

用geom函數表現圖形,geom中的aes參數映射數據,每一個geom函數添加一個圖層。

geom常用幾何參數常量賦值
color/fillcolor/fill=NA 消除線條或填充
alpha0 <= alpha <= 1
linetype線條形式(1:6)
size點的尺寸和線的寬度
shape點的形狀(0:25)

基本圖形

函數參數說明
geom_blank()空白
geom_curve(aes(yend,xend,curvature))
geom_segment(aes(yend,xend))
x, xend, y, yend, alpha, angle, color, curvature(曲率), linetype, size, arrow曲線
線段
geom_path(lineend, linejoin, linemitre)x, y, alpha, color, group, linetype, size(x為分類變量時必須設置group=1)路徑
geom_polygon(aes(group))x, y, alpha, color, fill, group, linetype, size多邊形
geom_rect(aes(xmin, ymin, xmax, ymax))xmax, xmin, ymax, ymin, alpha, color, fill, linetype, size矩形
geom_ribbon(aes(ymin, ymax))x, ymax, ymin, alpha, color, fill, group, linetype, size絲帶圖
geom_abline(aes(intercept, slope))x, y, alpha, color, linetype, size斜線
geom_hline(aes(yintercept))x, y, alpha, color, linetype, size水平線
geom_vline(aes(xintercept))x, y, alpha, color, linetype, size垂直線
geom_segment(aes(yend, xend))x, y, alpha, color, linetype, size線段
geom_spoke(aes(angle, radius))x, y, alpha, color, linetype, size輻條
them_blank <- theme(axis.text=element_blank(),axis.title = element_blank()axis.ticks=element_blank())p1=ggplot()+geom_spoke(aes(x=0,y=0,angle = 1:8, radius = 5))+them_blank+ggtitle('geom_spoke') a <- ggplot(economics, aes(date, unemploy)) a + geom_ribbon(aes(ymin=unemploy - 900, ymax=unemploy + 900))+them_blank+ggtitle('geom_ribbon') a + geom_path(lineend="butt", linejoin="round", linemitre=1)+them_blank+ggtitle('geom_path')

單變量

stat參數 : bin/count/identity

  • 若x為連續變量:stat= ”bin”
  • 若x離散變量:stat = “count”或stat = “identity”
continuous參數說明
geom_area()x, y, alpha, color, fill, linetype, size,stat={identity,bin}面積圖
geom_density(kernel = “gaussian”)x, y, alpha, color, fill, group, linetype, size, weight, adjust=1/2(調整帶寬倍率), stat={density,count,scaled (密度估計值)}核密度圖
geom_dotplot()x, y, alpha, color, fill點狀分布圖
geom_freqpoly()x, y, alpha, color, group, linetype, size頻率多邊形(類似直方圖)
geom_histogram(binwidth)x, y, alpha, color, fill, linetype, size, weight直方圖
geom_qq(aes(sample))x, y, alpha, color, fill, linetype, size, weightqq圖(檢測正態分布)
discrete
geom_bar()x, alpha, color, fill, linetype, size, weight, stat={count,prop (分組比例)}柱狀圖
c <- ggplot(mpg, aes(hwy)); c2 <- ggplot(mpg) c + geom_density()+them_blank+ggtitle('geom_density') c + geom_dotplot() +them_blank+ggtitle('geom_dotplot') c + geom_freqpoly()+them_blank+ggtitle('geom_freqpoly')

雙變量

continuous x
continuous y參數說明
geom_jitter(height , width)x, y, alpha, color, fill, shape, size抖點圖(避免重合),stat = “identity”
geom_point()x, y, alpha, color, fill, shape, size, stroke散點圖stat = “identity”
geom_quantile()x, y, alpha, color, group, linetype, size, weight四分位圖
geom_rug(sides)x, y, alpha, color, linetype, size,sides(地毯位置)地毯圖
geom_smooth()x, y, alpha, color, fill, group, linetype, size, weight擬合曲線,自動計算變量:y/ymin/ymax/se(標準誤)

geom_smooth(method = "auto", formula = y ~ x)

參數:
method: eg. “lm”, “glm”, “gam”, “loess”, “rlm”
formula :eg. y ~ x, y ~ poly(x, 2), y ~ log(x)
se : 是否繪制置信區間(默認為TRUE)
level : 用的置信區間水平(默認為95%)

if(!require(quantreg)) install.packages("quantreg")#四分位圖必須的包 e <- ggplot(mpg, aes(cty, hwy)) e + geom_jitter(height = 2, width = 2) +them_blank+ggtitle('geom_jitter') e + geom_quantile() +them_blank+ggtitle('geom_quantile') e + geom_smooth()+geom_rug(sides = "bl")+them_blank+ggtitle('geom_smooth')

兩連續變量分布圖參數說明
geom_density2d()x, y, alpha, colour, group, linetype, size, fill=…level…(自動計算變量)分布密度
geom_bin2d(binwidth)x, y, alpha, color, fill, linetype, size, weight矩形箱,stat = “bin2d”
geom_hex()x, y, alpha, colour, fill, size六角倉,stat = “binhex”
if(!require(hexbin)) install.packages("hexbin")#六角倉必須的包 df <- data.frame(x=rnorm(1000,0,100),y=rnorm(1000,10,50))h <- ggplot(df, aes(x, y)) h + geom_bin2d() +them_blank+ggtitle('geom_bin2d') h + geom_hex()+them_blank+ggtitle('geom_hex') h + geom_density2d() +them_blank+ggtitle('geom_density2d')

兩連續變量函數圖參數說明
geom_area()x, y, alpha, color, fill, linetype, size面積圖
geom_line()x, y, alpha, color, group, linetype, size折線圖
geom_step(direction = “hv”)x, y, alpha, color, group, linetype, size階梯圖
recent <- economics[economics$date > as.Date("2013-01-01"), ] p <- ggplot(recent, aes(date, unemploy))p + geom_area() +them_blank+ggtitle('geom_area') p + geom_line()+them_blank+ggtitle('geom_line') p + geom_step(direction = "hv") +them_blank+ggtitle('geom_step')

discrete x
continuous y參數說明
geom_col()x, y, alpha, color, fill, group, linetype, size柱狀圖
geom_boxplot()x, y, lower, middle, upper, ymax, ymin, alpha, color, fill, group, linetype, shape, size, weight, notch(是否缺口), width,outlier箱線圖
geom_dotplot(binaxis = “y”, stackdir = “center”)x, y, alpha, color, fill, group點狀分布圖(不重合)
geom_violin(scale = “area”)x, y, alpha, color, fill, group, linetype, size, weight小提琴圖
ggforce::geom_sina()點狀小提琴圖
p <- ggplot(mpg, aes(class, hwy)) p +geom_col() +them_blank+ggtitle('geom_col') p +geom_boxplot()+them_blank+ggtitle('geom_line') p +geom_dotplot(binaxis = "y", stackdir = "center") +them_blank+ggtitle('geom_dotplot') p +geom_violin(scale = "area")+them_blank+ggtitle('geom_violin') p +ggforce::geom_sina()+them_blank+ggtitle('geom_sina')

discrete x
discrete y參數說明
geom_count()x, y, alpha, color, fill, shape, size, stroke計數圖
ggplot(diamonds, aes(cut, color))+geom_count()

三變量

函數參數說明
geom_contour(aes(z))x, y, z, alpha, colour, group, linetype, size, weight,bins(等高線數量),binwidth(等高線寬度)等高線圖, …level…(輪廓高度,自動計算變量)
geom_raster(aes(fill))x,y,alpha,fill光柵(熱力圖)
geom_tile(aes(fill))x, y, alpha, color, fill, linetype, size, width瓦片(熱力圖)
p <- ggplot(faithfuld, aes(waiting, eruptions))p +geom_contour(aes(z = density)) +them_blank+ggtitle('geom_contour') p +geom_raster(aes(fill = density), hjust=0.5, vjust=0.5, interpolate=FALSE) +them_blank+ggtitle('geom_raster') p + geom_tile(aes(fill = density)) +them_blank+ggtitle('geom_tile') p + geom_raster(aes(fill = density)) +geom_contour(aes(z = density),colour = "white")+them_blank+ggtitle('raster+contour') #圖層順序很重要

文本

函數參數說明
geom_text(aes(label), nudge_x, nudge_y, check_overlap = TRUE)x, y, label, alpha, angle, color, family, fontface, hjust, lineheight, size, vjust
geom_label(aes(label), nudge_x, nudge_y, check_overlap = TRUE)x, y, label, alpha, angle, color, family, fontface, hjust, lineheight, size, vjust有背景框

參數:
nudge_x, nudge_y: 微調
check_overlap:是否過重疊
vjust,hjust: 對齊方式(0:1)
angle: 角度
lineheight:行間距
family: 字體
size: 字體大小
fontface: 字體格式(1:4, plain標準,bold加粗,italic斜體,bold.italic)

ggrepel包 : 文字不重疊
ggrepel:: geom_label_repel()
ggrepel:: geom_text_repel()

df=data.frame(x=c(1,1,3),y=c(3,2,1),t=c('A','B','C'))e=ggplot(df,aes(x,y)) e + geom_label(aes(label = t)) +them_blank+lims(x=c(0,5),y=c(0,5))+ggtitle('geom_label') e + geom_text(aes(label = t)) +them_blank+lims(x=c(0,5),y=c(0,5))+ggtitle('geom_text')

誤差可視化

函數參數說明
geom_crossbar(fatten)x, y, ymax, ymin, alpha, color, fill, group, linetype, size
geom_errorbar()x, ymax, ymin, alpha, color, group, linetype, size, width (also geom_errorbarh())
geom_linerange()x, ymin, ymax, alpha, color, group, linetype, size
geom_pointrange()x, y, ymin, ymax, alpha, color, fill, group, linetype, shape, size

aes(ymin,ymax) : ymin,ymax需要在aes參數內賦值

df <- data.frame(trt = factor(c('A', 'A', 'B', 'B')),resp = c(1, 5, 3, 4),group = factor(c(1, 2, 1, 2)),upper = c(1.1, 5.3, 3.3, 4.2),lower = c(0.8, 4.6, 2.4, 3.6) )dodge <- position_dodge(width=0.9) #位置微調 p <- ggplot(df, aes(trt, resp, fill = group,ymin = lower, ymax = upper))+geom_col(position = dodge)p + geom_crossbar(fatten = 2,position = dodge) +ggtitle('geom_crossbar') p + geom_errorbar(position = dodge, width = 0.25) +ggtitle('geom_errorbar') p +geom_linerange(position = dodge) +ggtitle('geom_linerange') p +geom_pointrange(position = dodge) +ggtitle('geom_pointrange')

地圖

函數參數說明
geom_map(aes(map_id), map)map_id, alpha, color, fill, linetype, size地圖

參數:
map_id:id/region
map: data.frame(x/long, y/lat, id/region) 或sp空間數據
Tips:
sf::st_read 讀取sp或json文件
sf::st_transform 轉換sf文件
地圖素材:
矢量地圖素材鏈接
shp數據地圖:GitHub ,GADM
Json數據地圖:阿里云, 百度Echarts

if(!require(maps)) install.packages("maps") # 載入地圖包(版本過老) data <- data.frame(murder = USArrests$Murder,state = tolower(rownames(USArrests)))map <- maps::map_data("state") ggplot(data, aes(fill = murder))+geom_map(aes(map_id = state), map = map) + expand_limits(x = map$long, y = map$lat)


Stats

ggplot2還提供一種替代方案,建立一個圖層用stat計算新變量 (e.g., count, prop)作圖。

  • 改變geom函數的stat默認值,如geom_bar(stat="count")
  • 調用stat_<FUNC>,如 stat_count(geom="bar")
  • 用..name..的語法格式,將stat計算變量映射到幾何對象,如stat_density2d(aes(fill = ..level..), geom = "polygon")
函數參數計算變量說明
stat_bin(binwidth, origin)x, y…count…, …ncount…, …density…, …ndensity…
stat_count(width = 1)x, y…count…, …prop…
stat_density(adjust = 1, kernel = “gaussian")x, y…count…, …density…, …scaled…
------------------------
stat_bin_2d(bins, drop = TRUE)x, y, fill…count…, …density…
stat_bin_hex(bins)x, y, fill…count…, …density…
stat_density_2d(contour = TRUE, n = 100)x, y, color, size…level…
stat_ellipse(level, segments, type = “t”)計算正常置信度橢圓
------------------------
stat_contour(aes(z))x, y, z, order…level…
stat_summary_hex(aes(z), bins, fun = max)x, y, z, fill…value…六邊形
stat_summary_2d(aes(z), bins, fun = mean)x, y, z, fill…value…矩形
stat_boxplot(coef)x, y…lower…, …middle…, …upper…, …width… , …ymin…, …ymax…
stat_ydensity(kernel = “gaussian”, scale = “area")x, y…density…, …scaled…, …count…, …n…, …violinwidth…, …width…
------------------------
stat_ecdf(n)x, y…x…, …y…計算經驗累積分布
stat_quantile(quantiles = c(0.1, 0.9), formula = y ~ log(x), method = “rq”)x, y…quantile…
stat_smooth(method = “lm”, formula = y ~ x, se=T, level=0.95)x, y…se…, …x…, …y…, …ymin…, …ymax…
------------------------
stat_function(aes(x = -3:3), n = 99, fun = dnorm, args = list(sd=0.5))x…x…, …y…計算每個x值的函數
stat_identity(na.rm = TRUE)保持原樣
stat_qq(aes(sample=1:100), dist = qt, dparam=list(df=5))sample, x, y…sample…, …theoretical…
stat_sum()x, y, size…n…, …prop…
stat_summary(fun.data = “mean_cl_boot”)將y值匯總在唯一x中
stat_summary_bin(fun.y = “mean”, geom = “bar”)將y值匯總在分箱x中
stat_unique()刪除重復項
set.seed(1492) df <- data.frame(x = rnorm(100) ) ggplot(df, aes(x)) + geom_density()+stat_function(fun = dnorm, colour = "red")+ggtitle('density vs. function')ggplot(faithful, aes(waiting, eruptions, color = eruptions > 3)) +geom_point() +stat_ellipse(type = "norm", linetype = 2) +stat_ellipse(type = "t")+ggtitle('stat_ellipse')

Scales

Scales傳遞數據給幾何對象,改變圖形的默認標尺。

p <- ggplot(mpg, aes(fl)) +geom_bar(aes(fill = fl))p + scale_fill_manual( # scale: scale, fill: 幾何對象, manual: 預處理的scale類型values = c("skyblue", "royalblue", "blue","navy"), #scale參數limits = c("d", "e", "p", "r"), #限制范圍breaks =c("d", "e", "p", "r"), #breaks to use in legend/axislabels = c("D", "E", "P", "R"), #labels to use in legend/axisname = "fuel") #legend/axis 標題

常用標尺格式

type: color,size,fill,shape,linetype,alpha,etc

scale_<type>_continuous() #連續變量映射 scale_<type>_discrete() #離散變量映射 scale_<type>_identity() #原始數據直接映射 scale_<type>_manual(value=c(…)) #自定義值范圍

坐標軸標尺

X & Y location scales說明
lims(x,y)/xlim()/ylim()
scale_x_continuous(breaks, labels,limits)刻度,標簽,值的范圍
scale_x_discrete(breaks, labels,limits)
scale_x_date(date_breaks , date_labels)日期間隔(“2 weeks”),日期顯示格式(%m/%d)
scale_x_datetime()時間日期,參數同date
scale_x_log10()log10 標尺
scale_x_reverse()x軸方向顛倒
scale_x_sqrt()

Color and fill scales

Continuous說明
scale_fill_distiller(palette = “Blues”)
scale_fill_gradient(low,high)漸變色調控
scale_fill_gradient2(low,mid,high,midpoint)2極漸變色
scale_fill_gradientn(values)n極漸變色
Discrete
scale_fill_hue()離散色階
scale_fill_brewer(palette = “Blues”)調色板
scale_fill_grey(start, end)灰色調

調色板離散色階palette選擇:
RColorBrewer::display.brewer.all()
連續色階選擇:
Also: rainbow(), heat.colors(), terrain.colors(), cm.colors()
RColorBrewer::brewer.pal()

#離散色階 p <- ggplot(mpg, aes(fl)) +geom_bar(aes(fill = fl))p +scale_fill_brewer(palette = "Blues")+ggtitle('scale_fill_brewer') p + scale_fill_grey(start = 0.2, end = 0.8,na.value = "red") +ggtitle('scale_fill_grey')#連續色階 p <- ggplot(mpg, aes(hwy))+ geom_dotplot(aes(fill = ..x..))p + scale_fill_distiller(palette = "Blues") +ggtitle('scale_fill_distiller') p + scale_fill_gradient(low="red", high="yellow") +ggtitle('scale_fill_gradient') p + scale_fill_gradient2(low="red", high="blue", mid = "white", midpoint = 25) +ggtitle('scale_fill_gradient2') p +scale_fill_gradientn(colours=topo.colors(6)) +ggtitle('scale_fill_gradientn')

Shape and size scales

shape說明
scale_shape()形狀
scale_shape_manual(values)
size
scale_size()大小
scale_radius(range)半徑

shape:

df <- data.frame(x=1:10,y=sample(1:10,10),s1=rnorm(10),s2=sample(1:4,10,replace = TRUE)) p <- ggplot(df, aes(x, y))+geom_point(aes(shape = factor(s2), size = s1, color=factor(s2))) p + scale_shape_manual(values = c(3:7)) p + scale_radius(range = c(1,6))

Coordinate Systems

Coordinate Systems參數說明
coord_cartesian()xlim,ylim笛卡爾坐標(默認)
coord_fixed()radio,xlim,ylim具有固定縱橫比的直角坐標
coord_flipxlim,ylimx和y翻轉(笛卡爾坐標)
coord_polartheta, start, direction極坐標
coord_trans()xtrans, ytrans,xlim,ylim變換笛卡爾坐標系,xtrans, ytrans接收函數名
coord_quickmap()
coord_map(projection = “ortho”,orientation )
projection, orienztation, xlim, ylim地圖投影 projections:{mercator (default), azequalarea, lagrange, etc.}
ggplot(mpg, aes(fl)) + them_blank+geom_bar()+coord_polar(theta = "x", direction=1)world <- map_data("world") worldmap <- ggplot(world, aes(x = long, y = lat, group = group)) +geom_path() +scale_y_continuous(breaks = (-2:2) * 30) +scale_x_continuous(breaks = (-4:4) * 45) worldmap + coord_map("ortho", orientation = c(41, -74, 0))

Position Adjustments

Position adjustments 對geoms進行位置調整。

geom參數賦值字符串

字符串: identity,jitterdodge (同時閃避和抖動),nudge(微距點固定距離)

geomposition
geom_bar/aera/densitydodge(并排), stack/fill(堆疊)
geom_pointjitter(減少點重疊)
geom_labelnudge(輕推來自點的標簽)

geom參數賦值position函數

position函數說明
position_dodge(width)抖動寬度(geom默認width=0.9,調用此函數時,width應設為0.9)
position_identity()不調整
position_jitter(width , height )
position_jitterdodge()
position_nudge(x = 0, y = 0)平移距離
position_stack(vjust = 1)對齊方式
position_fill(vjust = 1)
p <- ggplot(mpg, aes(fl, fill = drv))p + geom_bar(position = "dodge")+ggtitle('position = "dodge"') p + geom_bar(position = "fill")+ggtitle('position = "fill"') p + geom_bar(position = "stack")+ggtitle('position = "stack"')

Themes

theme(…)
設置主題包括title,axis,legend, panel, background,etc

主題函數說明
theme_bw(base_size,base_family)黑白主題
theme_grey()灰色主題(默認)
theme_dark()黑色主題
theme_void()空主題
theme_minimal()最小主題
ggtech::theme_tech()技術主題

控制theme元素函數(作為主題組件的參數出現):

元素函數說明
element_blank清空
element_rect(fill,color,size,linetype)邊框和背景
element_text(family,face, color, size,hjust, vjust,angle,lineheight, margin, debug)文字,參數:lineheight(行高), margin(邊緣), debug(是否矩形背景)
element_line(color,size,linetype,lineend,arrow)Line end style (round, butt, square),添加箭頭: grid::arrow(angle,length,ends=“last”/“first”/“both”)

Faceting

刻面通過類別變量將圖形分塊顯示。

刻面函數說明
facet_grid(var.row~var.col,scales,labeller)網格圖,單變量時var.row或var.col用點填充
facet_wrap(~var+var,nrow,ncol,scales,labeller)將1d的面板卷成2d網格(nrow*ncol)
ggforce::facet_zoom(x, y, xy, split = FALSE, zoom.size = 2)子集zoom,x,y,xy 賦值(邏輯值):選取x軸,y軸,xy交叉子集
t <- ggplot(mpg, aes(cty, hwy)) + geom_point() t + facet_grid(year ~ fl)# ggforce::facet_zoom ggplot(iris, aes(Petal.Length, Petal.Width, colour = Species)) +geom_point() +ggforce::facet_zoom(x = Species == "versicolor")

**scales參數:**坐標刻度自由
“fixed”(default,坐標尺度統一), “free”(坐標尺度自由),“free_x”,“free_y”

labeller參數: 調整刻面標簽

Annotations and Labels

Labels說明
ggtitle(label, subtitle = NULL)圖標題
labs(x,y,title,subtitle,caption)x/y軸標題
xlab(label)/ylab(label)x/y軸標題
Annotations說明
annotate(geom,…)geom注釋,其余參數為geom參數
annotate(“text”,x,y,label, parse=FALSE)文本注釋
annotate(“pointrange”, x , y, ymin, ymax)
annotate(“rect”, xmin, xmax, ymin, ymax)矩形注釋
annotate(“segment”,x, xend, y, yend, arrow)線段注釋

文本注釋參數parse:是否數學表達式, 更多公式語法可參考?plotmath
線段注釋參數arrow: 添加箭頭grid::arrow(angle,length,ends=”last” / ”first”/”both”)

Legends

theme(legend.position = "none"/"bottom"/"top"/"left"/"right") 在主題中設置 Legend
guides(…)設置legends幾何組件:colorbar, legend, or none (no legend)

guide函數作為scale或guides()的參數設置
guide_colorbar(title,label…)連續型變量
guide_legend(title,label…)離散型變量

Vector helpers

函數說明
stats::recoder(x_char,x_num,order=FALSE)重排序,返回factor/ord.factor
cut_interval(x,n,length)n組有相同寬度的觀測值
cut_number(x,n)n組有相同數量的觀測值
cut_width(x,width,center,boundary, closed = c(“right”,“left”))

混合圖

gridExtra包可以將多個ggplot2對象組合到一張圖中

gridExtra::grid.arrange(plot1,plot2,…,nrow,ncol)

ggplot2 extensions

ggplot2 now has an official extension mechanism. This means that others can now easily create their own stats, geoms and positions, and provide them in other packages. This should allow the ggplot2 community to flourish, even as less development work happens in ggplot2 itself. This page showcases these extensions.

總結

以上是生活随笔為你收集整理的R手册(Visualise)--ggplot2的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。