R手册(Visualise)--ggplot2

2023-11-03

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/fill color/fill=NA 消除线条或填充
alpha 0 <= 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')

0

单变量

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, weight qq图(检测正态分布)
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')

1

双变量

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')

2

两连续变量分布图 参数 说明
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')

h

两连续变量函数图 参数 说明
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')

10

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')

11

discrete x
discrete y
参数 说明
geom_count() x, y, alpha, color, fill, shape, size, stroke 计数图
ggplot(diamonds, aes(cut, color))+
  geom_count()

12

三变量

函数 参数 说明
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') #图层顺序很重要

13

文本

函数 参数 说明
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')

e

误差可视化

函数 参数 说明
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')

14

地图

函数 参数 说明
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)

15


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')

16

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/axis
  labels = c("D", "E", "P", "R"), #labels to use in legend/axis
  name = "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')

2

3

Shape and size scales

shape 说明
scale_shape() 形状
scale_shape_manual(values)
size
scale_size() 大小
scale_radius(range) 半径

shape:
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_flip xlim,ylim x和y翻转(笛卡尔坐标)
coord_polar theta, 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))

4 5

Position Adjustments

Position adjustments 对geoms进行位置调整。

geom参数赋值字符串

字符串: identity,jitterdodge (同时闪避和抖动),nudge(微距点固定距离)

geom position
geom_bar/aera/density dodge(并排), stack/fill(堆叠)
geom_point jitter(减少点重叠)
geom_label nudge(轻推来自点的标签)

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"')

6

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")

79

**scales参数:**坐标刻度自由
“fixed”(default,坐标尺度统一), “free”(坐标尺度自由),“free_x”,“free_y”

labeller参数: 调整刻面标签
8

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.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

R手册(Visualise)--ggplot2 的相关文章

  • R手册(Tidy+Transform)--tidyr

    文章目录 Reshape Data Split or Unit Cells Handle Missing Values tidyr Easily tidy data with spread and gather functions Resh
  • R手册(Tidy+Transform)--缺失处理(naniar and simputation)

    文章目录 naniar 缺失数据摘要 阴影矩阵 可视化缺失值变量分布关系 simputation make imputation simpler for missing data 缺失值是指粗糙数据中由于缺少信息而造成的数据的聚类 分组 删
  • R手册(Parallel Computing)--foreach

    R手册 Parallel Computing foreach foreach foreach 后端支持 library doParallel 为foreah包提供一个并行的后端 n cores lt detectCores logical
  • R手册(Tidy+Transform)--forcats

    forcats 分类变量数据处理 forcats for factor 函数 说明 factor x levels labels ordered as factor x fct expand f 添加更多级别 fct explicit na
  • R手册(Machine Learning)--mlr (Part 2)

    文章目录 Configuration 配置 Parallelization 并行 Imputation 插补 Feature Extraction 特征提取 1 Feature filtering 特征筛选 2 Feature select
  • R手册(Common)--R语言入门

    说明 本节中大部分内容摘自书籍 R语言实战 第2版 文章目录 RStudio Take control of your R code 数据处理一般流程 R 数据结构 R 运算符 概率函数 控制语句与循环语句 自定义函数 调试 拟合线性模型f
  • R手册(Import)--rvest

    文章目录 解析html 提取组件 提取 修改和提交形式的函数 浏览网站 解析html 函数 说明 read html x encoding x为a url或 a local path html nodes x css xpath 通过使用
  • R手册(Common)--tidyverse+tibble

    tidyverse是一系列包的组合 构建了一套完整的数据分析生态链 提供了一套整洁的数据导入 分析和建模方法 刷新了R语言原有的数据科学体系 文章目录 tidyverse Usage core tidyverse packages Impo
  • R手册(Common)--面向对象(R6 and S4)

    R 主要面向统计计算 似乎很少会用到面向对象的编程方法 但在统计计算中 在下列情形中使用面向对象的编程方法可以编程更有效率 文章目录 面向对象R6类 面向对象S4类 自定义S4类 实例化函数 S4的泛型函数 面向对象R6类 R 的面向对象
  • R手册(Visualise)--geomnet(ggplot2 extensions)

    文章目录 geomnet 返回ggplot2扩展主目录 geomnet Geom 网格图 关系图 geom net aes from id to id fontsize data stat net position identity na
  • R手册(Visualise)--ggplot2

    文章目录 Overview Geoms 基本图形 单变量 双变量 三变量 文本 误差可视化 地图 Stats Scales 常用标尺格式 坐标轴标尺 Color and fill scales Shape and size scales C
  • R手册(Common)--R语言基础包

    文章目录 环境设置 输入输出 文件操作 进度条 数据创建 数据选取及数据信息 列联表 内置常量 数学 矩阵运算 模型 其他函数 R语言基础包 base stats 环境设置 系统函数 函数 说明 options 显示或设置当前选项 digi
  • R手册(NLP)--wordcloud2

    文章目录 wordlcoud2函数 letterCloud函数 shiny支持 wordcloud2 R interface to wordcloud for data visualization Wordcloud2主要包括两个函数 wo
  • R手册(Syntax)--magrittr

    magrittr pipe lhs gt rhs forward pipe lhs为rhs第一个参数时 x gt f y 等价于 f x y lhs在任意位置时 用点 代替 z gt f x y arg 等价于 f x y arg z rh
  • R手册(Time Series)--forecast and prophet

    文章目录 forecast for Time Series and Linear Models 时间序列分析 模型 预测 ggplot2扩展 模型评估 prophet 构建模型 模型预测 可视化 交叉验证 时间序列分析 Time Serie
  • R手册(NLP)--text2vec

    文章目录 分词器 I O 处理 迭代器 支持 create 函数 向量化 主题模型 text2vec 这个 R 包提供了高性能和简洁的 API 来进行文本分析 自然语言处理 分词器 word tokenizer strings 英语分词器
  • R手册(Common)--data.table

    R语言data table包是自带包data frame的升级版 用于数据框格式数据的处理 最大的特点快 包括两个方面 一方面是写的快 代码简洁 只要一行命令就可以完成诸多任务 另一方面是处理快 内部处理的步骤进行了程序上的优化 使用多线程
  • R手册(Communicate)--R Markdown

    文章目录 Overview Rmd Structure YAML Header Parameters Set render options with YAML 初始文档信息 Text Embed code with knitr syntax
  • R手册(Visualise)--gganimate(ggplot2 extensions)

    文章目录 gganimate Create easy animations with ggplot2 返回ggplot2扩展主目录 gganimate Create easy animations with ggplot2 GitHub链接
  • R手册(Visualise)--GGally(ggplot2 extensions)

    本站已停止更新 查看最新内容请移至本人博客 Wilen s Blog 文章目录 GGally ggmatrix ggplot2矩阵 ggpairs ggplot2广义配对图 ggscatmat 纯粹定量变量的传统散点图矩阵 返回ggplot

随机推荐

  • Nodejs源码解析之module

    http blog csdn net leoleocs article details 50245677 module管理是Nodejs中比较有特色的部分 官方有详细的文档https nodejs org api modules html
  • el-tabs通过动态组件来更新单个tab页

    使用element ui的el tabs时 加载页面时会将所有单个tab页渲染出来 如果两个有联系的单个tab页 其中一个添加了数据 另一个tab页只有刷新才会显示出新的数据 使用动态组件来更新单个tab页 在data中定义tab列表 da
  • UnboundLocalError: cannot access local variable XXX where it is not associated with a value解决办法

    代码如图 a 1 def test a 1 test 此时运行代码会产生以下报错 UnboundLocalError cannot access local variable a where it is not associated wit
  • 查找两个字符串的相同代码块--Java

    前提 两个字符串中只有一个最大相同子串 public String getMaxSameString String str1 String str2 if str1 null str2 null String maxStr str1 len
  • 视图的定义与操作

    数据库系统 实验报告 实验名称 视图的定义与操作 实验地点 实验楼423 实验日期 一 实验目的及要求 1 掌握创建视图的SQL语句的用法 2 掌握修改视图的方法 3 熟悉视图更新与基本表更新的区别与联系 4 认识视图的作用 二 实验环境
  • vue获取+设置光标位置 光标定位 选择输入框文本

    版本 vue2 vant2 在vue是用ref r e f s 获取 d o m 的 在
  • STM32移植LVGL踩坑集锦

    这篇文章我主要讲解一下我在移植LVGL时所遇到的一些坑以及解决方法 LVGL的移植过程可以参考我前面的文章 http t csdn cn QSVOO 第一个 问题 在lvgl8 1以前的版本可能会出现MY DISP HOR RES 和 MY
  • QtDesigner中如何手动添加工具栏toolBar

    如下图 只需要把Action拖到工具栏中即可
  • Android scroller控件,Android Scroller完全解析

    在Android中 任何一个控件都是可以滚动的 因为在View类当中有scrollTo 和scrollBy 这两个方法 如下图所示 这两个方法的主要作用是将View ViewGroup移至指定的坐标中 并且将偏移量保存起来 另外 mScro
  • ES的基本介绍和使用

    增 删 改 查 全部遵循refult 风格 使用postman来新建一个文档 1 增加 http localhost 9200 blog1 article 1 id 1 title 在弹性搜索中创建索引时 content 为什么呢 因为ma
  • nginx 之 root 和 alias

    目录 1 alias 语法 2 root 语法 3 差别 1 alias 语法 Syntax alias path Default Context location 定义指定location的替换 例如 使用以下配置 location i
  • 计算机网络:流量控制和拥塞控制

    拥塞控制和流量控制 流量控制 如果发送方把数据发送得过快 接收方可能会来不及接收 这就会造成数据的丢失 TCP的流量控制是利用滑动窗口机制实现的 接收方在返回的数据中会包含自己的接收窗口的大小 以控制发送方的数据发送 拥塞控制 拥塞控制就是
  • win10 装MySQL Instance Configuration Wizerd 卡死/未响应问题

    一 若此前安装过MySQL应当先将此前的文件残留清除干净 见链接http blog csdn net aerchi article details 50432934 二 隐藏文件ProgramData MySQL也应当删除 偷懒方法就是在安
  • Linux命令·chmod

    chmod命令用于改变linux系统文件或目录的访问权限 用它控制文件或目录的访问权限 该命令有两种用法 一种是包含字母和操作符表达式的文字设定法 另一种是包含数字的数字设定法 Linux系统中的每个文件和目录都有访问许可权限 用它来确定谁
  • Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 8.x提示报错

    1 在使用统一脚手架的时候提示了报错信息如下 ERROR in app containers App SiderMenu SiderPanel style scss node modules css loader node modules
  • java实现进程控制块_操作系统:进程管理和IO控制

    一 进程管理 进程管理包括进程控制 进程调度 进程同步与通信 死锁控制四个内容 一 进程控制 进程是操作系统中运行的基本单位 包括程序段 数据段和进程控制段 操作系统通过进程控制块 PCB 管理进程 每一个PCB唯一标示一个进程 它存储进程
  • 沉浮于各种文件型数据库 hsqldb h2 还是derby

    原始发表时间 2009 09 10 经过几天的折腾终于还是心碎了 前前后后为了这个数据库共计花费了约2周的时间 系统采用的是经典技术框架 Spring 2 0 5 Hibernate 3 2 iBatis 2 2 0 用于连接文件型数据库的
  • CI/CD持续集成之git命令

    持续集成主要步骤 持续集成的定义 互联网开发已经形成一套标准的流程 最重要的组成部分就是持续集成 持续集成的好处就是 频繁将代码集成到主干 它的优点 1快速发现错误 2 防止分支大幅度偏离主干 意义 就是让产品进行持续迭代 同时保持高质量交
  • git学习1之基本原理

    2019独角兽企业重金招聘Python工程师标准 gt gt gt Git 基础 那么 简单地说 Git 究竟是怎样的一个系统呢 请注意接下来的内容非常重要 若你理解了 Git 的思想和基本工作原理 用起来就会知其所以然 游刃有余 在开始学
  • R手册(Visualise)--ggplot2

    文章目录 Overview Geoms 基本图形 单变量 双变量 三变量 文本 误差可视化 地图 Stats Scales 常用标尺格式 坐标轴标尺 Color and fill scales Shape and size scales C